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 = "0.3"
Install the JavaScript package with your preferred package manager:
shell
npm install @tauri-store/vue
shell
pnpm add @tauri-store/vue
shell
deno add npm:@tauri-store/vue
shell
bun add @tauri-store/vue
shell
yarn add @tauri-store/vue
Usage
- 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>