版权版权1、 外层包围 1、 外层包围 keep-alive作用将组件实例缓存下来







2、清除组件缓存2、清除组件缓存使用keep-alive 的 exclude="组件名" 属性







补充知识:vue 简单的页面刷新或者跳转页面的数据保存问题补充知识:补充知识:vue 简单的页面刷新或者跳转页面的数据保存问题当我们想刷新页面也保存当时的数据的时候,会遇到这样那样的问题,其实,仅仅的几行代码就什么都解决了,下面是代码(js):
var vm = new Vue({
el:'.search_moduel',
data:{

history:[] //存储查询历史记录的数据
},
methods:{

//刷新页面或者从别的页面进入,提取this.history的值

getPageData:function(){

this.history = JSON.parse(localStorage.getItem('this.history'));//使用getItem方法的前提是,你再自己需要的地方使用了setItem方法

}
},
//钩子函数,在实例被创建之后被调用,调用getPageData()
created:function(){

this.getPageData();
}
});
var vm = new Vue({
el:'.search_moduel',
data:{

history:[] //存储查询历史记录的数据
},
methods:{

//刷新页面或者从别的页面进入,提取this.history的值

getPageData:function(){

this.history = JSON.parse(localStorage.getItem('this.history'));//使用getItem方法的前提是,你再自己需要的地方使用了setItem方法

}
},
//钩子函数,在实例被创建之后被调用,调用getPageData()
created:function(){

this.getPageData();
}
});以上这篇Vue切换组件实现返回后不重置数据,保留历史设置操作就是小编分享给大家的全部内容了,希望能给大家一个参考。