「Vue」watch基本用法

应用于监视路由地址改变,如有新地址(即路由地址改变)即执行自定义方法

methods: {
        itemShow() {
            this.$axios.get('item/item/'+this.id+'?token='+this.$store.state.token).then(ret => {
                console.log(ret)
            })
        },
        
    },
watch: {
        '$route.path'(newVal,oldVal) {
            if (newVal) {
                this.itemShow()
            }
        }
    },
View Code
原文地址:https://www.cnblogs.com/wrxblog/p/10598729.html