Vuex,iView UI面包屑導(dǎo)航使用擴(kuò)展詳解
本案例是基于Vuex的公共數(shù)據(jù)庫,你在了解本案例之前要了解Vuex的使用方法。
https://www.iviewui.com/components/breadcrumb
打開網(wǎng)址我們可以知道這個組件的面包屑導(dǎo)航是基于路由跳轉(zhuǎn)的。但是我們項目中常常用到單頁面查詢面包屑導(dǎo)航。小生開始為這個糾結(jié)好久。然后和小伙伴一起研究出來一套單頁面不用路由跳轉(zhuǎn)的使用方法。
先看看效果圖
1,首次進(jìn)來

2,查詢結(jié)果

3,再次點(diǎn)擊面包屑導(dǎo)航

4,查詢結(jié)果

基本的效果是這樣的
下面看代碼
<template>
<div class="members">
<Breadcrumb separator=">" > //面面包屑導(dǎo)航組件,用“>”隔開
<BreadcrumbItem v-for="(item,index) in accountList"> // 用v-for遍歷循環(huán)賬號數(shù)組
<span class="select_span" @click="queryAgentMember(item)"> //商品這里放置賬號,調(diào)用查詢函數(shù)實現(xiàn)點(diǎn)擊賬號查詢
<Icon v-if="index==0" type="ios-home-outline"></Icon> // v-if判斷第一個賬號的圖標(biāo)
<Icon v-if="index>0" type="android-person"></Icon> // v-if判斷不是第一個賬號的圖標(biāo)
<span>{{item}}</span> // 圖標(biāo)后面的賬號
</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ù)進(jìn)行判斷,在有賬號的情況下
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ù)進(jìn)行判斷,在沒有賬號的情況下
this.Account = this.childAccount
}
let data = {
'memberAccount':this.Account,
'sort': '1',
'type': '1'
};
this.queryAgentMemberInfo(data).then((res) => {
this.queryAgentMemberdataList = this.queryAgentMemberInfoList;
})
},
// 面包屑導(dǎo)航點(diǎn)擊查詢實時變更函數(shù)
queryAgentMember(account){
let end = this.accountList.indexOf(account); // 定義一個變量等于傳入的賬號的下標(biāo)
this.accountList = this.accountList.slice(0,end+1); // 利用這個下標(biāo)對張海數(shù)組進(jìn)行截取
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: { // 這里還要對表格賬號點(diǎn)擊查詢進(jìn)行判斷
click:()=>{
//同樣的先判斷賬號數(shù)組里面有沒有當(dāng)前查詢的賬號,這里也是在沒有的額情況下
if(this.accountList.indexOf(params.row.account)==-1){
//沒有就將當(dāng)前查詢的賬號添加到賬號數(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: '團(tuán)隊人數(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面包屑導(dǎo)航使用擴(kuò)展詳解就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Vue基礎(chǔ)學(xué)習(xí)之項目整合及優(yōu)化
這篇文章主要給大家介紹了關(guān)于Vue基礎(chǔ)學(xué)習(xí)之項目整合及優(yōu)化的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用Vue具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-06-06

