Vue中使用keepAlive不缓存问题(已解决)
1.查看app.vue文件,这个是重点,不能忘记加(我就是忘记加了keep-alive)
2.查看router.js
3.在需要缓存的页面加入如下代码
beforeRouteEnter(to, from, next) { if (from.name == 'creditInformation' || from.name == 'cityList') { to.meta.isBack = true; } next(); }, activated() { this.getData() this.$route.meta.isBack = false this.isFirstEnter = false },
附上钩子函数执行顺序:
-
不使用keep-alive
beforeRouteEnter --> created --> mounted --> destroyed -
使用keep-alive
beforeRouteEnter --> created --> mounted --> activated --> deactivated
再次进入缓存的页面,只会触发beforeRouteEnter -->activated --> deactivated 。created和mounted不会再执行。
于此文记之!!!