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-vue = "2"Install the JavaScript package with your preferred package manager:
shell
npm install @tauri-store/vueshell
pnpm add @tauri-store/vueshell
deno add npm:@tauri-store/vueshell
bun add @tauri-store/vueshell
yarn add @tauri-store/vueUsage
- Enable the required permissions in your capabilities file:
json
{
"identifier": "vue",
"windows": ["*"],
"permissions": ["vue:default", "core:event:default"]
}- Register the plugin with Tauri:
rust
tauri::Builder::default()
.plugin(tauri_plugin_vue::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");- Create a store:
typescript
import { createStore } from '@tauri-store/vue';
export const store = createStore('counter', { counter: 0 });TIP
createStore is also exported as store.
- Start it:
typescript
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.
- Use the store in your Vue components:
vue
<script>
import { store } from '@/stores/counter';
</script>
<template>
<div>
<p>Counter: {{ store.counter }}</p>
<button type="button" @click="() => store.counter++">
<span>Increment</span>
</button>
</div>
</template>