码迷,mamicode.com
首页 > 其他好文 > 详细

vue2 vue-rout

时间:2017-06-29 23:47:59      阅读:374      评论:0      收藏:0      [点我收藏+]

标签:简单   ges   component   redirect   pat   rect   技术   new   com   

vue 2.0的路由比起1.0简单了许多,分为以下几个步骤;

1.创建路由块和视图块;

to里面是要切换的路径名称

<div id="app">
			<div>
				<router-link to="/home">主页</router-link>
				<router-link to="/news">新闻</router-link>
			</div>
			<div>
				<router-view></router-view>
			</div>
</div>

 2.写组件

     var Home={
            template:‘<h3>我是主页</h3>‘
        };
        var News={
            template:‘<h3>我是新闻</h3>‘
        };

 3、

//配置路由
        var routes=[
            {path:‘/home‘, component:Home},
            {path:‘/news‘, component:News},
        //重镜像,相当于是主页 {path:‘*‘, redirect:‘/home‘} ];

 4、创建路由实例

var router = new VueRouter({
				routes :routes //routes是一个参数 
			})

 5、

//最后挂到vue上
        new Vue({
            router,
            el:‘#box‘
        });

 

效果:

技术分享

 

vue2 vue-rout

标签:简单   ges   component   redirect   pat   rect   技术   new   com   

原文地址:http://www.cnblogs.com/lm-it/p/7096741.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!