zoukankan      html  css  js  c++  java
  • npm安装vuex及防止页面刷新数据丢失

    npm install vuex
    

    在项目scr目录下新建store文件夹,在store文件夹下新建index.js文件。

    import Vue from 'vue';
    import Vuex from 'vuex';
    Vue.use(Vuex);
    
    
    const state={
    	accountInfo:{
    
    	}
    }
    
    const mutations={
    	initUser(state,payload){
    		state.accountInfo=Object.assign(state.accountInfo,payload);
    		localStorage.setItem('accountInfo',JSON.stringify(state.accountInfo));
    	},
    	clear(state){
    		state.accountInfo={
    			
    		}
    	}
    }
    //防止页面刷新vuex中的数据丢失
    for(var item in state){
       localStorage.getItem(item)?state[item] = JSON.parse(localStorage.getItem(item)): false;
    }
    
    
    
    export default  new Vuex.Store({
        state,
        mutations
    })
    

      

  • 相关阅读:
    L208
    L207
    L206
    L205 EE
    L204
    监控glusterfs
    监控elssticSearch健康状态
    防火墙
    创建逻辑卷
    编译安装nginx,并使用systemd管理nginx
  • 原文地址:https://www.cnblogs.com/luyuefeng/p/8334472.html
Copyright © 2011-2022 走看看