vue.js - 更改网址后立即停止观看
问题描述
我想知道如何改变这个
computed: {
currentUrl () {
return this.$route.path
},
},
watch: {
currentUrl (newURl, firstUrl) {
if ((!this.$cookiz.get('firstUrl')) && ((this.check === undefined) || (this.check === 0))) {
this.showPopUp()
}
}
},
手表在检测到第一次更改或网址后停止一次。任何想法将不胜感激。非常感谢。
解决方案
与其在内部创建观察者watch
,不如在钩子内部创建它created
,然后通过调用自身来删除它:
created() {
this.unwatchCurrentUrl = this.$watch('currentUrl', (newURl, firstUrl) => {
const condition1 = !this.$cookiz.get('firstUrl')
const condition2 = this.check === undefined
const condition3 = this.check === 0
if (condition1 && (condition2 || condition3)) {
this.showPopUp()
// Remove watcher
this.unwatchCurrentUrl()
}
})
}
推荐阅读
- python - Set user_id in Mlflow
- oracle - SELECT sys_context('userenv','ip_address') FROM dual returns IPV4 but sometimes it returns IPV6
- laravel - 方法 Illuminate\Support\Str::replace 不存在
- css - How Do I Center "Quick Links" Section On Footer Of My Shopify Website
- vba - Word toc 使用 VBA 调整显示级别
- algorithm - 树中具有颜色条件的最长路径
- node.js - How to achieve 100% Round Robin with BullMQ?
- git - 如何在 Windows 上仔细检查我的 SSH 凭据?
- jupyter-notebook - Poor chart quality on high DPI display (4K) - how to set scaling?
- javascript - Arduino to Raspberry Pi Communication over BLE