//在index.js中{path: '/SearchContent',name: 'SearchContent',component: SearchContent,meta: {keepAlive: false,//此组件不需要被缓存isBack:false }},{path: '/Shop',name: 'Shop',component: Shop,meta: {keepAlive: false, isBack:false//判断上一个页面}},//在searchContent中beforeRouteEnter(to, from, next) {// 设置下一个路由的 metaif(from.name == 'Shop'){to.meta.isBack = true;to.meta.keepAlive = true;} // 让 A 缓存,即不刷新next();},components:{"app-brands":Brand},//注意activated只能在keep-alive组件中调用activated() {if(!this.$route.meta.isBack){// 如果isBack是false,表明需要获取新数据,否则就不再请求,直接使用缓存的数据this.getData();this.getTree();}// 恢复成默认的false,避免isBack一直是true,导致下次无法获取数据this.$route.meta.isBack=false},//在进入页面时调用接口请求数据,当数据请求完成,第二次进入页面时,就会执行activated函数mounted(){this.getData()this.getTree()},
1200字范文,内容丰富有趣,写作的好帮手!