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 = "4"Install the JavaScript package with your preferred package manager:
shell
npm install @tauri-store/piniashell
pnpm add @tauri-store/piniashell
deno add npm:@tauri-store/piniashell
bun add @tauri-store/piniashell
yarn add @tauri-store/piniaUsage
- 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:
typescript
import { createApp } from 'vue';
import { createPinia } from 'pinia';
import { createPlugin } from '@tauri-store/pinia';
const app = createApp(App);
const pinia = createPinia();
pinia.use(createPlugin());
app.use(pinia);
app.mount('#app');TIP
createPlugin is also exported as TauriPluginPinia.
- Define your Pinia store:
typescript
import { ref } from 'vue';
import { defineStore } from 'pinia';
export const useStore = defineStore('counter', () => {
const counter = ref(0);
return { counter };
});- Start it:
typescript
const store = useStore();
await store.$tauri.start();TIP
Stores won't be saved nor synchronized until you start them, but you can enable the autoStart option to make them start automatically.
Nuxt
If you are using Nuxt, you can create a Nuxt plugin to enable it for Pinia:
typescript
import type { Pinia } from 'pinia';
import { TauriPluginPinia } from '@tauri-store/pinia';
// See: https://pinia.vuejs.org/core-concepts/plugins.html#Nuxt-js
export default defineNuxtPlugin(({ $pinia }) => {
($pinia as Pinia).use(TauriPluginPinia());
});