vue.js引用vue router的方法:首先安装npm包,代码为【npm install vue-router --save】;然后利用【v-link】这个【directive】。
vue.js引用vue router的方法:
安装
基于传统,我更喜欢采用npm包的形式进行安装。
npm install vue-router --save
当然,官方采用了多种方式进行安装,包括bower,cdn等。
基本用法
在HTML文档中使用,只需要利用v-link这个directive就行了,如:
Go to view-a
ps: v-link还支持activeClass用于指定链接活跃时的css样式。replace属性为true的时候可以让链接在跳转的时候不会留下历史记录。
而在ES5中使用,需要先创建路由器实例,随后传入配置参数即可,如:
var router = new VueRouter();
router.map({
'/view-a': {
component: ViewA
},
'/view-b': {
component: ViewB
}
});
router.start(App, '#app');