Store
Este plugin proporciona un almacén clave-valor persistente. Esta es una de las muchas opciones para gestionar el estado en tu aplicación. Consulta la visión general de gestión de estado para obtener más información sobre opciones adicionales.
Este almacén te permitirá meintener el estado en un archivo que se puede guardar y cargar bajo demanda, incluso entre reinicios de la app. Ten en cuenta que este proceso es asíncrono, lo que requerirá manejarlo dentro de tu código. Se puede usar tanto en la webview como dentro de Rust.
Plataformas Soportadas
Sección titulada “Plataformas Soportadas”Este plugin requiere una versión de Rust de al menos 1.77.2
| Plataforma | Nivel | Notas |
|---|---|---|
| windows | ||
| linux | ||
| macos | ||
| android | ||
| ios |
Configuración
Sección titulada “Configuración”Instala el plugin store para comenzar.
Usa el gestor de paquetes de tu proyecto para agregar la dependencia:
npm run tauri add storeyarn run tauri add storepnpm tauri add storedeno task tauri add storebun tauri add storecargo tauri add store-
Ejecuta el siguiente comando en la carpeta
src-tauripara agregar el plugin a las dependencias del proyecto enCargo.toml:cargo add tauri-plugin-store -
Modifica
lib.rspara inicializar el plugin:src-tauri/src/lib.rs #[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() {tauri::Builder::default().plugin(tauri_plugin_store::Builder::new().build()).run(tauri::generate_context!()).expect("error while running tauri application");} -
Instala los bindings de JavaScript utilizando tu gestor de paquetes de JavaScript preferido:
npm install @tauri-apps/plugin-storeyarn add @tauri-apps/plugin-storepnpm add @tauri-apps/plugin-storedeno add npm:@tauri-apps/plugin-storebun add @tauri-apps/plugin-store
import { load } from '@tauri-apps/plugin-store';// when using `"withGlobalTauri": true`, you may use// const { load } = window.__TAURI__.store;
// Create a new store or load the existing one,// note that the options will be ignored if a `Store` with that path has already been createdconst store = await load('store.json', { autoSave: false });
// Set a value.await store.set('some-key', { value: 5 });
// Get a value.const val = await store.get<{ value: number }>('some-key');console.log(val); // { value: 5 }
// You can manually save the store after making changes.// Otherwise, it will save upon graceful exit// And if you set `autoSave` to a number or left empty,// it will save the changes to disk after a debounce delay, 100ms by default.await store.save();use tauri::Wry;use tauri_plugin_store::StoreExt;use serde_json::json;
#[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() { tauri::Builder::default() .plugin(tauri_plugin_store::Builder::default().build()) .setup(|app| { // Create a new store or load the existing one // this also put the store in the app's resource table // so your following `store` calls (from both Rust and JS) // will reuse the same store.
let store = app.store("store.json")?;
// Note that values must be serde_json::Value instances, // otherwise, they will not be compatible with the JavaScript bindings. store.set("some-key", json!({ "value": 5 }));
// Get a value from the store. let value = store.get("some-key").expect("Failed to get value from store"); println!("{}", value); // {"value":5}
// Remove the store from the resource table store.close_resource();
Ok(()) }) .run(tauri::generate_context!()) .expect("error while running tauri application");}LazyStore
Sección titulada “LazyStore”También hay una API de JavaScript de alto nivel LazyStore que solo carga el almacén en el primer acceso
import { LazyStore } from '@tauri-apps/plugin-store';
const store = new LazyStore('settings.json');Migrando desde v1 y v2 beta/rc
Sección titulada “Migrando desde v1 y v2 beta/rc”import { Store } from '@tauri-apps/plugin-store';import { LazyStore } from '@tauri-apps/plugin-store';with_store(app.handle().clone(), stores, path, |store| { store.insert("some-key".to_string(), json!({ "value": 5 }))?; Ok(())});let store = app.store(path)?;store.set("some-key".to_string(), json!({ "value": 5 }));Permisos
Sección titulada “Permisos”De forma predeterminada, todos los comandos y alcances (scopes) potencialmente peligrosos del plugin están bloqueados y no se puede acceder a ellos. Debes modificar los permisos en tu configuración de capabilities para habilitarlos.
Consulta la Visión General de Capacidades para obtener más información y la guía paso a paso para usar permisos de plugins.
{ "permissions": [ ..., "store:default", ]}Permiso Predeterminado
Este conjunto de permisos configura qué tipo de operaciones están disponibles desde el plugin store.
Permisos Otorgados
Todas las operaciones están habilitadas por defecto.
Este conjunto de permisos predeterminado incluye lo siguiente:
allow-loadallow-get-storeallow-setallow-getallow-hasallow-deleteallow-clearallow-resetallow-keysallow-valuesallow-entriesallow-lengthallow-reloadallow-save
Tabla de Permisos
| Identificador | Descripción |
|---|---|
|
|
Habilita el comando clear sin ningún alcance preconfigurado. |
|
|
Deniega el comando clear sin ningún alcance preconfigurado. |
|
|
Habilita el comando delete sin ningún ámbito preconfigurado. |
|
|
Deniega el comando delete sin ningún ámbito preconfigurado. |
|
|
Habilita el comando entries sin ningún ámbito preconfigurado. |
|
|
Deniega el comando entries sin ningún ámbito preconfigurado. |
|
|
Habilita el comando get sin ningún ámbito preconfigurado. |
|
|
Deniega el comando get sin ningún ámbito preconfigurado. |
|
|
Habilita el comando get_store sin ningún ámbito preconfigurado. |
|
|
Deniega el comando get_store sin ningún ámbito preconfigurado. |
|
|
Habilita el comando has sin ningún ámbito preconfigurado. |
|
|
Deniega el comando has sin ningún ámbito preconfigurado. |
|
|
Habilita el comando keys sin ningún ámbito preconfigurado. |
|
|
Deniega el comando keys sin ningún ámbito preconfigurado. |
|
|
Habilita el comando length sin ningún ámbito preconfigurado. |
|
|
Deniega el comando length sin ningún ámbito preconfigurado. |
|
|
Habilita el comando load sin ningún ámbito preconfigurado. |
|
|
Deniega el comando load sin ningún ámbito preconfigurado. |
|
|
Habilita el comando reload sin ningún ámbito preconfigurado. |
|
|
Deniega el comando reload sin ningún ámbito preconfigurado. |
|
|
Habilita el comando reset sin ningún ámbito preconfigurado. |
|
|
Deniega el comando reset sin ningún ámbito preconfigurado. |
|
|
Habilita el comando save sin ningún ámbito preconfigurado. |
|
|
Deniega el comando save sin ningún ámbito preconfigurado. |
|
|
Habilita el comando set sin ningún ámbito preconfigurado. |
|
|
Deniega el comando set sin ningún ámbito preconfigurado. |
|
|
Habilita el comando values sin ningún ámbito preconfigurado. |
|
|
Deniega el comando values sin ningún ámbito preconfigurado. |
© 2026 Colaboradores de Tauri. CC-BY / MIT