1. 程式人生 > >vue-router動態利用配置內容

vue-router動態利用配置內容


script裡面動態操作routers裡面的配置可以用 this.routerthis.router包含多種可操作的型別,可以實現動態的把routers裡面的配置顯示到HTML頁面當中。

1-this.router.path//2this.router.name //當前路徑配置的名稱
3-this.$router.matched //當前路由匹配項(為物件)
以name為例

<li v-for="item in matched "></li>
methods:{
this.matched = this.$route.matched.filter(item => item.name);
}


如上程式碼,可以拿到routers裡面配置的一些列資訊,動態顯示到HTML中。