admin管理员组文章数量:1323715
Say I have a router map looks like this:
router.map({
'/a_example': {
ponent: A
},
'/b_example': {
ponent: B
},
There is a Ajax Request every 1 sec on ponent A. I load /a_example
in the browser and click the link on the ponent A
to go to /b_example
. Now the browser is showing ponent B as expected. However, the Ajax Request doesn't stop and still sends request every 1 sec.
My guess is that vue-router still keeps ponent A under the hood so that it won't hit performance issues.
Anyway all I've found out in .html is this keep-alive
thing. But it's deactive by default and I am sure I did't use it.
Is there some kind of options I can make use of?
Say I have a router map looks like this:
router.map({
'/a_example': {
ponent: A
},
'/b_example': {
ponent: B
},
There is a Ajax Request every 1 sec on ponent A. I load /a_example
in the browser and click the link on the ponent A
to go to /b_example
. Now the browser is showing ponent B as expected. However, the Ajax Request doesn't stop and still sends request every 1 sec.
My guess is that vue-router still keeps ponent A under the hood so that it won't hit performance issues.
Anyway all I've found out in http://vuejs.github.io/vue-router/en/view.html is this keep-alive
thing. But it's deactive by default and I am sure I did't use it.
Is there some kind of options I can make use of?
Share Improve this question asked Jan 30, 2016 at 17:28 francisfengfrancisfeng 8181 gold badge10 silver badges23 bronze badges2 Answers
Reset to default 4Vue-router provides a number of optional transition hooks. You can stop sending ajax requests inside the deactivate
hook.
Vue.ponent('ponent-A', {
route: {
deactivate: function () {
//stop sending requests
}
}
})
In the latest version of VueRouter (v.2.1.1), you can use an In-Component Guard:
beforeRouteLeave
const Foo = {
template: `...`,
beforeRouteLeave (to, from, next) {
// stop your requests here
// ...
next()
}
}
本文标签: javascriptHow to destroy a component when building SPA with Vuejs and vuerouterStack Overflow
版权声明:本文标题:javascript - How to destroy a component when building SPA with Vue.js and vue-router? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742123002a2421809.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论