「Vue」watch基本用法

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

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
相关文章
相关标签/搜索