同一页面内重复点击进行跳转,只在第一次跳转时加载created和mounted,第二次直接使用页面缓存了,发现id=298和id=299在页面上的数据是一样的,是什么原因呢?
其实是因为没有触发vue的created或者mounted钩子,因为你进入的router.name是一样的,虽然参数变了,但路由没有监听到。
解决方法:
在App.vue文件中,添加代码如下:
添加之后,立马见效!!
<template>
<div id="app">
<router-view :key="key"/>
</div>
</template>
<script>
export default {
name: 'App',
computed:{
key(){
return this.$route.name !== undefined? this.$route.name + +new Date(): this.$route + +new Date()
}
}
}
</script>