Vuex,iView UI面包屑導航使用擴展詳解
本案例是基于Vuex的公共數(shù)據(jù)庫,你在了解本案例之前要了解Vuex的使用方法。
https://www.iviewui.com/components/breadcrumb
打開網(wǎng)址我們可以知道這個組件的面包屑導航是基于路由跳轉(zhuǎn)的。但是我們項目中常常用到單頁面查詢面包屑導航。小生開始為這個糾結(jié)好久。然后和小伙伴一起研究出來一套單頁面不用路由跳轉(zhuǎn)的使用方法。
先看看效果圖
1,首次進來
2,查詢結(jié)果
3,再次點擊面包屑導航
4,查詢結(jié)果
基本的效果是這樣的
下面看代碼
<template> <div class="members"> <Breadcrumb separator=">" > //面面包屑導航組件,用“>”隔開 <BreadcrumbItem v-for="(item,index) in accountList"> // 用v-for遍歷循環(huán)賬號數(shù)組 <span class="select_span" @click="queryAgentMember(item)"> //商品這里放置賬號,調(diào)用查詢函數(shù)實現(xiàn)點擊賬號查詢 <Icon v-if="index==0" type="ios-home-outline"></Icon> // v-if判斷第一個賬號的圖標 <Icon v-if="index>0" type="android-person"></Icon> // v-if判斷不是第一個賬號的圖標 <span>{{item}}</span> // 圖標后面的賬號 </span> </BreadcrumbItem> </Breadcrumb> <Table class="table_a" :border="showBorder" :stripe="showStripe" :show-header="showHeader" :height="fixedHeader ? 250 : ''" :size="tableSize" :data="queryAgentMemberdataList" :columns="tableColumns3"></Table> </div> </template> <script> import { mapActions,mapState } from "vuex"; export default { data () { return { Account:'', //定義一個賬號變量 accountList:[], //定義一個數(shù)組裝賬號 queryAgentMemberdataList:[], //這是表格列表數(shù)據(jù) } }, methods:{ ...mapActions('account', [ 'queryAgentMemberInfo', ] ), //查詢函數(shù) search(acc) { this.time(); if(acc ){ //對函數(shù)參數(shù)進行判斷,在有賬號的情況下 this.Account = acc; // 如果有就賦值給Account }else if(this.childAccount === ""){ //繼續(xù)判斷沒有下級賬號 this.Account = this.userDetail.account; // 如果沒有就等于后臺返回的賬號 if(this.accountList.indexOf(this.userDetail.account)==-1){ // 再一次判斷這個賬號在不在賬號數(shù)組里面,這里是不在的情況下 this.accountList.push(this.userDetail.account) // 不在就push到賬號數(shù)組 } }else { //對函數(shù)參數(shù)進行判斷,在沒有賬號的情況下 this.Account = this.childAccount } let data = { 'memberAccount':this.Account, 'sort': '1', 'type': '1' }; this.queryAgentMemberInfo(data).then((res) => { this.queryAgentMemberdataList = this.queryAgentMemberInfoList; }) }, // 面包屑導航點擊查詢實時變更函數(shù) queryAgentMember(account){ let end = this.accountList.indexOf(account); // 定義一個變量等于傳入的賬號的下標 this.accountList = this.accountList.slice(0,end+1); // 利用這個下標對張海數(shù)組進行截取 this.search(account) //調(diào)用查詢函數(shù)更新表格數(shù)據(jù) }, }, computed: { ...mapState(['userDetail']), ...mapState( "account",['queryAgentMemberInfoList',]), tableColumns3 () { let columns = []; if (this.showCheckbox) { columns.push({ type: 'selection', align: 'center' }) } if (this.showIndex) { columns.push({ type: 'index', align: 'center' }) } columns.push({ title: '會員賬號', sortable: true, render: (h, params) => { if (params.row.account === this.Account) { } return h('Span',{ props: { type: 'text' }, style: { color: '#4ca5e9', cursor: 'pointer' }, on: { // 這里還要對表格賬號點擊查詢進行判斷 click:()=>{ //同樣的先判斷賬號數(shù)組里面有沒有當前查詢的賬號,這里也是在沒有的額情況下 if(this.accountList.indexOf(params.row.account)==-1){ //沒有就將當前查詢的賬號添加到賬號數(shù)組 this.accountList.push(params.row.account) } this.search(params.row.account); //查詢函數(shù) } } },params.row.account) } }); columns.push({ title: '賬號名稱', key: 'name' }); columns.push({ title: '彩票錢包余額', key: 'accountBalance', sortable: true }); columns.push({ title: '團隊人數(shù)', key: 'childCount' }); columns.push({ title: '注冊時間', key: 'create_Time', sortable: true, width: 200 }); columns.push({ title: '最后登錄時間', key: 'last_LoginTime', sortable: true, width: 150 }); columns.push({ title: '下級總額', key: 'childAmount' }); return columns; }, }, watch:{ userDetail(){ this.search() } } } </script>
這里的代碼不可以直接使用,但是方法都在,希望讀者可以看懂。
以上這篇Vuex,iView UI面包屑導航使用擴展詳解就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
jdk1.8+vue elementui實現(xiàn)多級菜單功能
這篇文章主要介紹了jdk1.8+vue elementui實現(xiàn)多級菜單功能,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-09-09Vue動態(tài)加載圖片在跨域時無法顯示的問題及解決方法
這篇文章主要介紹了解決VUE動態(tài)加載圖片在跨域時無法顯示的問題,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-03-03Vue2.5 結(jié)合 Element UI 之 Table 和 Pagination 組件實現(xiàn)分頁功能
這篇文章主要介紹了Vue2.5 結(jié)合 Element UI 之 Table 和 Pagination 組件實現(xiàn)分頁功能,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2018-01-01