进行路由跳转的时候能触发吗?我发现我进行路由跳转的时候没有触发beforeDestory里面的函数,但是有段代码需要在组件销毁之前执行,请问我应该怎么做呢?
https://jsfiddle.net/44w37p34/ 刚刚有个朋友给我发了一个demo,我发现他的beforeDestory在路由跳转的时候触发了,但是我的一直都不行,请问是什么原因呢
習慣沉默2017-07-05 10:48:40
我试了一下,切换路由的时候能触发执行beforeDestroy方法,示例如下。
const Home = {
template: `
<p>
<p class="section">Some section foo</p>
<p class="section">Some section foo</p>
<p class="section">Some section foo</p>
<p class="section">Some section foo</p>
</p>
`,
mounted() {
console.log("Home mounted");
},
beforeDestroy() {
console.log("Home destroy");
}
};
const Test = {
template: `
<p>
<p class="section">Some section test</p>
<p class="section">Some section test</p>
<p class="section">Some section test</p>
<p class="section">Some section test</p>
</p>
`,
mounted() {
console.log("Test mounted");
},
beforeDestroy() {
console.log("Test destroy");
}
};