0
点赞
收藏
分享

微信扫一扫

Vue项目菜单跳转传参

萧让听雪 2022-01-07 阅读 56

vue菜单之跳转传参
    a.vue 跳转 b.vue
    
    第一种:类似get方式,浏览器地址栏显示参数
    
    在a.vue中这样写:
    
    data() {
        retuen {
            id: '3'
        }
    },
    methods: {
        getById(){
            this.$router.push({
                path: '/example/tree', // 跳转菜单的路径
                query: {
                    id: this.id        // 传入的参数
                }
            })
        }
    }
    
    
    在b.vue中这样写:
    
    data() {
        retuen {
            id: ''
        }
    },
    // 在生命周期函数中接受参数
    created() {
        this.id = this.$route.query.id
        console.log( this.id )
    }
    
    
    第二种:类似post方式,浏览器地址栏不显示参数
    
    在a.vue中这样写:
    
    data() {
        retuen {
            id: '3'
        }
    },
    methods: {
        getById(){
            this.$router.push({
                name: 'Tree',          // 跳转菜单的路径
                params: {
                    id: this.id        // 传入的参数
                }
            })
        }
    }
    
    
    在b.vue中这样写:
    
    data() {
        retuen {
            id: ''
        }
    },
    // 在生命周期函数中接受参数
    created() {
        this.id = this.$route.params.id
        console.log( this.id )
    }

举报

相关推荐

0 条评论