当前位置:网站首页>Using cache in vuex to solve the problem of data loss in refreshing state
Using cache in vuex to solve the problem of data loss in refreshing state
2022-06-26 18:39:00 【Whoopsina】
In the use of vuex In the process of , We often encounter the problem of refreshing the page state Data loss in , In this case, the local cache can be used to solve
Be careful :
The instance code is uniapp project , You can convert cache methods to native
// stay index.js in
state: {
userInfo: null
},
getters:{
userInfo(state) {
if(!state.userInfo){
state.userInfo = uni.getStorageSync('userInfo');
}
return state.userInfo
}
},
mutations: {
setUserInfo(state,data) {
state.userInfo = data;
uni.setStorageSync('userInfo',data);
}
},
// In components state and getters You can get it in
computed:{
...mapGetters(['userInfo']);
...mapState(['userInfo']);
},
Be careful
At one's own use vuex A pit in the middle :
vuex Official documents : https://vuex.vuejs.org/zh/
- data The properties of and computed The attribute in cannot have the same name ,
however state and getters The attributes in can have the same name , They don't interfere with each other . - Page to use vuex When there are many data , You can use more …mapState,…mapGetters wait
- To be updated
边栏推荐
- 判断某个序列是否为栈的弹出序列
- JVM入个门(1)
- Deep learning: numpy
- CD-CompactDisk
- CLion断点单步调试
- Leetcode 238 product of arrays other than itself
- Introduction to Ethereum Technology Architecture
- Xlua get button registration click event of ugui
- Tag dynamic programming - preliminary knowledge for question brushing -2 0-1 knapsack theory foundation and two-dimensional array solution template
- 项目实战六:分布式事务-Seata
猜你喜欢
随机推荐
50 lines of code to crawl TOP500 books and import TXT documents
Enter n integers and output the number of occurrences greater than or equal to half the length of the array
(树) 树状数组
8VC Venture Cup 2017 - Final Round C. Nikita and stack
gdb安装
物联网协议的王者:MQTT
爬取豆瓣读书Top250,导入sqlist数据库(或excel表格)中
Numpy's Matplotlib
GDB installation
Micro service single sign on system (SSO)
Eigen库计算两个向量夹角
Deep learning: numpy
知识点总结
微信小程序 uniapp 左滑 删除 带删除icon
链游开发成品源码 链游系统开发详情说明
将字符串B插入字符串A,有多少种插入办法可以使新串是一个回文串
Solidity - contract inheritance sub contract contains constructor errors and one contract calls the view function of another contract to charge gas fees
基于tensorflow的手写数字识别
To: Apple CEO Cook: great ideas come from constantly rejecting the status quo
Handwritten promise all









