复制链接 https://codesandbox.io/s/vue-template-c2gtb
复制步骤
Open https://codesandbox.io/s/vue-template-c2gtb
Click on 'Go to Page with nested router' link
Click on 'commit event', it will show an alert box
Now change the nested route by clicking 'change nested route to reporting'
期望什么? 路由更改为报告,但未显示“您好”警报框。
实际情况是什么? 它再次显示“ hello”警报框。
答案 0 :(得分:1)
您应该更改观察者以忽略旧值与新值相同的情况:
watch: {
event: {
handler(newVal,oldVal) {
if(oldVal === newVal) return; // <--- the important part
switch (this.event.id) {
case 'new_requirement': {
alert('hello');
break;
}
default:
}
},
},
},