Getting started
Supported Tauri Version
This plugin requires Tauri 2.0
or later.
Install
Install the Rust crate by adding the following to your Cargo.toml
file:
toml
[dependencies]
tauri-plugin-pinia = 0.7
Install the JavaScript package with your preferred package manager:
sh
npm install tauri-plugin-pinia
sh
pnpm add tauri-plugin-pinia
sh
yarn add tauri-plugin-pinia
sh
bun add tauri-plugin-pinia
Usage
- Enable the required permissions in your capabilities file:
json
{
"identifier": "pinia",
"windows": ["*"],
"permissions": ["pinia:default", "core:event:default"]
}
- Register the plugin with Tauri:
rust
tauri::Builder::default()
.plugin(tauri_plugin_pinia::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
- Enable the plugin for Pinia:
ts
import { createApp } from 'vue';
import { createPinia } from 'pinia';
import { createPlugin } from 'tauri-plugin-pinia';
const app = createApp(App);
const pinia = createPinia();
pinia.use(createPlugin());
app.use(pinia).mount('#app');
TIP
createPlugin
is also exported as TauriPluginPinia
.
- Define your Pinia store:
ts
import { ref } from 'vue';
import { defineStore } from 'pinia';
export const useCounterStore = defineStore('counter', () => {
const counter = ref(0);
function increment() {
counter.value++;
}
return {
counter,
increment,
};
});
- Start the plugin:
ts
import { useCounterStore } from './stores/counter';
const counterStore = useCounterStore();
counterStore.$tauri.start();
TIP
The stores won't be saved nor synchronized until you call the start
method.