「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

 

posted @ 2019-03-26 10:46  子谦0618  阅读(101)  评论(0编辑  收藏  举报