zoukankan      html  css  js  c++  java
  • Vuex 页面刷新后store保存的数据会丢失 取cookie值

    在store.js中

    
    
    export default new vuex.Store({
    // 首先声明一个状态 state
    state:{
        pcid: '',
        postList: [],
      }
      //更新状态
      mutations:{
            changepcId(state, _pcid){
                state.pcid = _pcid;
            },
            changepostList(state, _postList){
                state.postList = _postList;
                Cookies.set('postList', _postList);
            },
      }
    }

    在A页面存数据不变

    this.$store.commit( 'changepostList', res );

    在B页面取数据

        data(){
                return{
                    postimg: '',
               
                    datalist:[],
                  
                }
            },
        created(){//页面刷新后store保存的数据会丢失 取cookie值
                if(this.$store.state.postList.length ===0 ){
                    this.datalist =JSON.parse(Cookies.get('postList')) ;
                }else{
                    this.datalist = this.$store.state.postList;
                }
    
                if(this.postimg === ''){
                    this.postimg = Cookies.get('postimg');
                }else{
                    this.postimg = this.$store.state.postimg;
                }
            },
  • 相关阅读:
    QTP err.number
    QTP参数化
    QTP基础
    QTP脚本补录
    QTP添加对象入库
    系统自带计算器自动化
    QTP安装
    App 测试
    本地化和国际化测试
    剑桥雅思写作高分范文ESSAY30
  • 原文地址:https://www.cnblogs.com/dudu123/p/10220474.html
Copyright © 2011-2022 走看看