Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
952 views
in Technique[技术] by (71.8m points)

vue router 跳转变化 之前将 值传入到组件中,组件收到过渡动画的class名称

点击一个按钮,跳转router时 ,怎么做到,将 指定的值(这个值是有2中情况的)传入到组件中,过度。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

用导航钩子函数
https://router.vuejs.org/zh-c...

<div id="app">
    <router-link to="/a">aaaa</router-link>
    <router-link to="/b">index</router-link>
    
    <transition :name="v">
        <router-view ></router-view>
    </transition>
            
</div>
    
        

            const router = new VueRouter({
                routes: [
                    {
                        path: '/a',
                        component: {
                            template: '<span>a</span>'
                        }
                    },
                    {
                        path: '/b',
                        component: {template: '<span>b</span>'}
                    }
                ]
            })
            
            var app = new Vue({
                el: '#app',
                data: {
                    v: 1
                },
                router,
                watch: {
                    '$route'(to,from){
                        this.v = 2;
                    }
                }
            });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...