我的应用程序中集成了对讲机,我需要拨打电话window.Intercom('update');
每次我的网址改变时。
我知道我可以添加它mounted()
但我宁愿不修改我的所有组件并直接使用导航守卫 https://router.vuejs.org/en/advanced/navigation-guards.html。 (主要是为了避免在10个不同的地方有相同的代码。
目前我有:
router.afterEach((to, from) => {
eventHub.$off(); // I use this for an other things, here is not important
console.log(window.location.href ) // this prints the previous url
window.Intercom('update'); // which means that this also uses the previous url
})
这运行intercom('update')
在更改 url 之前,而我需要在 url 更改后运行它。
是否有一个钩子在 url 更改时运行?
我怎样才能做到这一点?
Thanks
不确定这是否有效,因为您已经拥有的似乎应该没问题,但这里...
Try 观看$route object https://router.vuejs.org/en/essentials/dynamic-matching.html#reacting-to-params-changes进行更改
new Vue({
// ...
watch: {
'$route': function(to, from) {
Intercom('update')
}
}
})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)