当前位置:网站首页>[boutique] Pinia Persistence Based on the plug-in Pinia plugin persist
[boutique] Pinia Persistence Based on the plug-in Pinia plugin persist
2022-07-06 23:52:00 【Liang Yunliang】
preparation
First step : install pinia
npm install pinia --save
The second step : newly build store Catalog , establish index.ts
import {
createPinia } from "pinia"
const store = createPinia()
export default store
The third step :main.ts Use in store
import {
createApp } from 'vue'
import store from '@/store'
const app = createApp(App)
app.use(store)
app.mount('#app')
Step four : newly build user.ts
import {
defineStore } from "pinia"
export const useUserStore = defineStore({
id:'user',
state() {
return {
name: '',
age: 0
}
}
})
Step five : stay vue Page usage
<template>
User:{
{ name }} == {
{ age }}
<br>
<button @click="fun"> Modified value </button>
</template>
<script setup lang="ts"> import {
useUserStore} from "@/store/module/user" import {
storeToRefs} from "pinia" const userStore = useUserStore() const {
name, age} = storeToRefs(userStore) const fun = () => {
userStore.name = "zhangsan" userStore.age = 18 } </script>
result
Open the page , Click the page button , The displayed user information changes , Refresh the page and return to its original appearance .
Using plug-ins pinia-plugin-persist Persistence
First step : Installing a plug-in pinia-plugin-persist
npm install pinia-plugin-persist --save
The second step : modify store Under folder index.ts
import {
createPinia } from "pinia"
import piniaPluginPersist from 'pinia-plugin-persist'
const store = createPinia()
store.use(piniaPluginPersist)
export default store
The third step : modify user.ts, To add persist
import {
defineStore} from "pinia"
export const useUserStore = defineStore({
id: "user",
state: () => {
return {
name: '',
age: 0
}
},
persist: {
enabled: true,
strategies: [
{
key: 'wego_user',
storage: localStorage
}
]
}
})
notes : stay strategies You can specify which data to cache , such as :
strategies: [
{
storage: localStorage, paths: ['token','name'] }
]
test
Run the program , Open the page and click the button , Data changes , Close the page and open it again , The page still shows the changed data , here F12, Will see :
边栏推荐
- Penetration test --- database security: detailed explanation of SQL injection into database principle
- Should the jar package of MySQL CDC be placed in different places in the Flink running mode?
- DAY FIVE
- Hydrogen future industry accelerates | the registration channel of 2022 hydrogen energy specialty special new entrepreneurship competition is opened!
- 1000字精选 —— 接口测试基础
- Daily question brushing record (XV)
- Cas d'essai fonctionnel universel de l'application
- app通用功能測試用例
- CRMEB 商城系统如何助力营销?
- 【2022全网最细】接口测试一般怎么测?接口测试的流程和步骤
猜你喜欢

电脑重装系统u盘文件被隐藏要怎么找出来

STM32通过串口进入和唤醒停止模式

公链与私链在数据隐私和吞吐量上的竞争

AVL树到底是什么?

DAY FOUR

Competition between public and private chains in data privacy and throughput

leetcode:236. 二叉树的最近公共祖先

DAY TWO
![[communication] optimal power allocation in the uplink of two-layer wireless femtocell network with matlab code](/img/47/741b89d94a2b0003937f32bdedfa19.png)
[communication] optimal power allocation in the uplink of two-layer wireless femtocell network with matlab code

DAY THREE
随机推荐
The programmer said, "I'm 36 years old, and I don't want to be rolled, let alone cut."
DAY FIVE
STM32通过串口进入和唤醒停止模式
A novice asks a question. I am now deployed on a single machine. I submitted an SQL job and it runs normally. If I restart the service job, it will disappear and I will have to
leetcode:236. 二叉树的最近公共祖先
Per capita Swiss number series, Swiss number 4 generation JS reverse analysis
okcc呼叫中心的订单管理时怎么样的
《数字经济全景白皮书》保险数字化篇 重磅发布
Knowledge * review
There are only two TXT cells in the ArrayExpress database. Can you only download the sequencing run matrix from line to ENA?
设计一个抢红包系统
若依请求url中带有jsessionid的解决办法
Can async i/o be implemented by UDF operator and then called by SQL API? At present, it seems that only datastre can be seen
app通用功能測試用例
在Docker中分分钟拥有Oracle EMCC 13.5环境
Gradle knowledge generalization
After 3 years of testing bytecan software, I was ruthlessly dismissed in February, trying to wake up my brother who was paddling
How can Oracle CDC deserialize with jsondebeziumdeserializationschema
Experiment 4: installing packages from Gui
Close unregistering application XXX with Eureka with status down after Eureka client starts