Watch 监听路由

<template>
    <div class="h1">{{name }}</div>
</template>

<script>
    export default {
        name: "Test",
        data() {
            return {
                name : '',
            }
        },
        created() {
        }, watch: { 
            '$route': {
                    handler(newVal, oldVal) {
                        this.getview(newVal, oldVal)
                    },
                    deep: true,
                    immediate: true,
                } 
        },methods:{
            getview(to, from){
                this.name = this.$route.query.name 
            }
        }
    }
</script> 

Logo

前往低代码交流专区

更多推荐