vue+vue-route實現麪包屑

 <div>
        <div v-for="(item,index) in levelList" :key="item.path" style="display:inline">
        // 如果是最後一個的話
          <span v-if="index==levelList.length-1">{{ item.meta.title}}</span>
          // 如果不是最後一個的話
          <a v-else style="color:black" @click.prevent="handleLink(item)">{{ item.meta.title }}></a>
        </div>
  </div>
	methods: {
    getBreadcrumb() {
      // 這裏做一個篩選,如果有title,則進行顯示
      let matched = this.$route.matched.filter(
        item => item.meta && item.meta.title
      );
      // 這裏是爲了將首頁插入到麪包屑中
      const first = matched[0];
      if (!this.isindex(first)) {
        matched = [{ path: "/admin/index", meta: { title: "首頁" } }].concat(
          matched
        );
      }
      // 這裏把路由信息加入到數組中
      this.levelList = matched.filter(
        item => item.meta && item.meta.title && item.meta.breadcrumb !== false
      );
    },
    isindex(route) {
      const name = route && route.name;
      if (!name) {
        return false;
      }
      return name.trim() === "index";
    },
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章