tauri-plugin-pinia
Persistent Pinia stores for Tauri, with automatic synchronization between multiple windows.
Install
Install the plugin by adding the following to your Cargo.toml file:
[]
= 0.1
Install the JavaScript package with your preferred package manager:
# or
# or
Usage
- Enable the required permissions in your capabilities file:
- Register the plugin with Tauri:
src-tauri/src/main.rs
- Enable the plugin for Pinia:
src/index.ts
import { createApp } from 'vue';
import { createPinia } from 'pinia';
import { TauriPluginPinia } from 'tauri-plugin-pinia';
const app = createApp(App);
const pinia = createPinia();
pinia.use(TauriPluginPinia);
app.use(pinia);
app.mount('#app');
- Create your Pinia store:
src/stores/counter.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!
import { useCounterStore } from './stores/counter';
const counterStore = useCounterStore();
counterStore.$tauri.start();