当前位置:网站首页>Pinia uses plug-ins for persistent storage.
Pinia uses plug-ins for persistent storage.
2022-07-27 04:37:00 【Taoist priest IOT】
1. install pinia Persistence plug-in
npm i pinia-plugin-persist -S
Optimize 1:pinia Put it in main.js Make the main file appear a little bloated , Now let's deal with this problem
1. stay src Create a new one in the directory index.js file , Write the following , Register the plug-in for use
import {
createPinia } from 'pinia'
// Introduce persistence plug-ins
import piniaPluginPersist from 'pinia-plugin-persist'
const store = createPinia()
// Use this plug-in
store.use(piniaPluginPersist)
// export
export default store
2. stay main.js Register in
import {
createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from '@/store'
const app = createApp(App)
app.use(store).use(router).mount('#app')
3. stay store Create a new folder test.js file , Let's use the persistence plug-in
import {
defineStore } from 'pinia'
import axios from 'axios'
export default defineStore('main', {
state: () => {
return {
count: 10,
name: ' Hezhiwei ',
list: [{
name: 'ipone',
price: 5800,
count: 1
},
{
name: 'huawei',
price: 5800,
count: 2
}],
timuList: []
}
},
// Use this plug-in , Turn on the data cache
persist: {
// The default storage here is session
enabled: true,
strategies: [
{
//key The name of
key: 'my_user',
// Change default storage , I changed to localStorage
storage: localStorage,
// You can choose which to enter local Storage , So you don't have to store everything
// The default is to store all
paths: ['list']
}
]
}
})
边栏推荐
- The new Internet era has come. What new opportunities will Web 3.0 bring us
- Head detached from origin/... Causes push failure
- STM32 serial port based on Hal library accepts interrupts and idle interrupts
- F - Pre-order and In-order(Atcoder 255)
- GenericServlet为什么有两个init方法
- Shel automatically sets directory permissions
- 数据分析师岗位分析
- RSA asymmetric encryption and decryption signature verification tool
- ISG index shows that the it and business service market in the Asia Pacific region fell sharply in the second quarter
- 微信小程序编辑头像
猜你喜欢

Chapter 6: cloud database

第六章:云数据库

Understand kingbasees V9 in one picture

微服务的feign调用header头被丢弃两种解决方案(附源码)

安全第四次课后练习

Wechat applet rotation map

好用的shell快捷键

BSN IPFs (interstellar file system) private network introduction, functions, architecture and characteristics, access instructions

Is the e-commerce billing system important? How should the platform choose billing service providers?

Ribbon load balancing strategy and configuration, lazy loading and hungry loading of ribbon
随机推荐
Database leader Wang Shan: strive for innovation and carefully Polish high-quality database products
Shell的正则表达式入门、常规匹配、特殊字符:^、$、.、*、字符区间(中括号):[ ]、特殊字符:\、匹配手机号
【HCIP】重发布、重分布、重分发实验
Eureka service registry
匿名命名管道, 共享内存的进程间通信理解与使用
ELS square display principle
Elastic certification test: 30 day FastPass Study Guide
使用kubesphere图形界面dashboard开启devops功能
Using webmvcconfigurer to intercept interface requests is being enhanced (with source code)
P1438 boring sequence line segment tree + difference
How to set user-defined display for Jiaming Watch
5.component动态组件的展示
Brightcove任命Dan Freund为首席营收官
2022杭电多校联赛第三场 题解
QString转换char*
IIC 通信协议 (一)
[final review of software engineering] knowledge points + detailed explanation of major problems (E-R diagram, data flow diagram, N-S box diagram, state diagram, activity diagram, use case diagram...)
【软件工程期末复习】知识点+大题详解(E-R图、数据流图、N-S盒图、状态图、活动图、用例图....)
Standard C language 13
好用移动APP自动化测试框架哪里找?收藏这份清单就好了!