vue路由

vue路由允許我們使用不同的url訪問不同的內容。

vue路由的使用過程:

1、下載安裝庫;

2、定義路由組件;const foo={template:'<div>a<div>'}

2、定義路由;const routes=[{path:'/foo',componet:foo},{}]

3、實例化路由,將路由加入;const router=new VueRouter({routes})

4、將router參數注入vue實例,使得整個程序都有路由功能;const v=new vue({router}).$mount('作用標籤id')

5、路由調用:

<router-link to> <router-link>

router-link導航,to指定鏈接,相當於<a>

6、路由出口:

<router-view><router-view>

所有的路由效果顯示在路由出口里。

7:路由屬性:

to:使用router.push(),會留下歷史記錄;

replace:使用router.replace(),不會留下歷史記錄;

append:在當前路徑下拼接;

tag:渲染成某種標籤;

active-class:路由模糊匹配下使用樣式;

exact-active-class:精確匹配下使用的樣式.

原文地址:https://www.cnblogs.com/Zhengxiaoxiao/p/10522847.html