vue+element-ui的后台項目封裝組件--面包屑的封裝


最近項目打算重構,項目的模塊幾乎都是以后台查詢展示的傳統的增刪改差模式,所以卑微的我想要自己封裝一下tab,

子組件--可以添加icon的。

 1 <template>
 2   <div id="bread">
 3     <div class="bread-title">
 4       <div
 5         v-for="(item, index) in breadlist"
 6         :key="index"
 7         class="bread-curry"
 8         @click="tab(index)"
 9         :class="[index == active ? 'active' : '']"
10       >
11         <span class="icon  bread-icon"></span>
12         <span v-if="item.path" :to="{ path: '/' + item.path }">{{
13           item.title
14         }}</span>
15         <span v-else>{{ item.title }}</span>
16       </div>
17     </div>
18   </div>
19 </template>
20 <script>
21 export default {
22   props: {
23     breadlist: {
24       type: Array
25     },
26     title: {
27       type: String
28     },
29     icon: {
30       type: String
31     },
32     path: {
33       type: String
34     },
35     active: {
36       type: Number
37     }
38   },
39   data() {
40     return {};
41   },
42   methods: {
43     tab(index) {
44       this.$emit("tab", index);
45     }
46   }
47 };
48 </script>
49 <style lang="less" scoped>
50 // .bread-title {
51 //   height: 42px;
52 //   line-height: 42px;
53 // }
54 .bread-curry {
55   display: inline-block;
56   line-height: 42px;
57   cursor: pointer;
58   padding: 0 20px;
59   color: #666666;
60   font-size: 16px;
61   font-weight: bold;
62   line-height: 40px;
63   border-radius: 3px 3px 0 0;
64 }
65 .bread-icon {
66   width: 21px;
67   height: 23px;
68   margin-right: 5px;
69   vertical-align: middle;
70 }
71 .active {
72   color: #1a68b5;
73   cursor: default;
74   background-color: #e3edf7;
75   border-bottom-color: transparent;
76 }
77 </style>

子組件創建完之后在父組件里面引入

 1   <flight-bread
 2       :breadlist="breadlist"
 3       :active="active"
 4       @tab="tab"
 5     ></flight-bread>
 6 <script>
 7 import flightBread from "@/components/flightBread.vue";
 8 export default{
 9 components: {
10     flightBread,
11   
12   },
13     data() {
14         return {
15           breadlist: [
16             { title: "查詢費率", path: "", id: 1 },
17             { title: "費率設置", path: "", id: 2 },
18             { title: "鋪貨特貨碼設置", path: "", id: 3 }
19           ],
20           active: 0,
21         }
22     },
23      methods: {
24          tab(childData) {
25           this.active = childData;
26     },
27     }
28 }
29 </script>        

封裝的這個tab面包屑只是在同一個頁面控制顯示隱藏,如果要跳轉到其他頁面的話,只需要在父組件傳值那里添加path 的路徑就可以,如果不跳轉到其他的頁面的話,path建議不設置這個字段,因為這個字段是控制子組件里面的to顯示的,

卑微前端,記錄自己的項目封裝的組件,方便以后自己用,如果有哪里不合理,請各路大神多多指教。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM