Vuex,iView UI面包屑導(dǎo)航使用擴(kuò)展詳解
本案例是基于Vuex的公共數(shù)據(jù)庫,你在了解本案例之前要了解Vuex的使用方法。
https://www.iviewui.com/components/breadcrumb
打開網(wǎng)址我們可以知道這個(gè)組件的面包屑導(dǎo)航是基于路由跳轉(zhuǎn)的。但是我們項(xiàng)目中常常用到單頁面查詢面包屑導(dǎo)航。小生開始為這個(gè)糾結(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)賬號(hào)數(shù)組 <span class="select_span" @click="queryAgentMember(item)"> //商品這里放置賬號(hào),調(diào)用查詢函數(shù)實(shí)現(xiàn)點(diǎn)擊賬號(hào)查詢 <Icon v-if="index==0" type="ios-home-outline"></Icon> // v-if判斷第一個(gè)賬號(hào)的圖標(biāo) <Icon v-if="index>0" type="android-person"></Icon> // v-if判斷不是第一個(gè)賬號(hào)的圖標(biāo) <span>{{item}}</span> // 圖標(biāo)后面的賬號(hà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:'', //定義一個(gè)賬號(hào)變量 accountList:[], //定義一個(gè)數(shù)組裝賬號(hào) queryAgentMemberdataList:[], //這是表格列表數(shù)據(jù) } }, methods:{ ...mapActions('account', [ 'queryAgentMemberInfo', ] ), //查詢函數(shù) search(acc) { this.time(); if(acc ){ //對(duì)函數(shù)參數(shù)進(jìn)行判斷,在有賬號(hào)的情況下 this.Account = acc; // 如果有就賦值給Account }else if(this.childAccount === ""){ //繼續(xù)判斷沒有下級(jí)賬號(hào) this.Account = this.userDetail.account; // 如果沒有就等于后臺(tái)返回的賬號(hào) if(this.accountList.indexOf(this.userDetail.account)==-1){ // 再一次判斷這個(gè)賬號(hào)在不在賬號(hào)數(shù)組里面,這里是不在的情況下 this.accountList.push(this.userDetail.account) // 不在就push到賬號(hào)數(shù)組 } }else { //對(duì)函數(shù)參數(shù)進(jìn)行判斷,在沒有賬號(hào)的情況下 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í)時(shí)變更函數(shù) queryAgentMember(account){ let end = this.accountList.indexOf(account); // 定義一個(gè)變量等于傳入的賬號(hào)的下標(biāo) this.accountList = this.accountList.slice(0,end+1); // 利用這個(gè)下標(biāo)對(duì)張海數(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: '會(huì)員賬號(hào)', sortable: true, render: (h, params) => { if (params.row.account === this.Account) { } return h('Span',{ props: { type: 'text' }, style: { color: '#4ca5e9', cursor: 'pointer' }, on: { // 這里還要對(duì)表格賬號(hào)點(diǎn)擊查詢進(jìn)行判斷 click:()=>{ //同樣的先判斷賬號(hào)數(shù)組里面有沒有當(dāng)前查詢的賬號(hào),這里也是在沒有的額情況下 if(this.accountList.indexOf(params.row.account)==-1){ //沒有就將當(dāng)前查詢的賬號(hào)添加到賬號(hào)數(shù)組 this.accountList.push(params.row.account) } this.search(params.row.account); //查詢函數(shù) } } },params.row.account) } }); columns.push({ title: '賬號(hào)名稱', key: 'name' }); columns.push({ title: '彩票錢包余額', key: 'accountBalance', sortable: true }); columns.push({ title: '團(tuán)隊(duì)人數(shù)', key: 'childCount' }); columns.push({ title: '注冊(cè)時(shí)間', key: 'create_Time', sortable: true, width: 200 }); columns.push({ title: '最后登錄時(shí)間', key: 'last_LoginTime', sortable: true, width: 150 }); columns.push({ title: '下級(jí)總額', key: 'childAmount' }); return columns; }, }, watch:{ userDetail(){ this.search() } } } </script>
這里的代碼不可以直接使用,但是方法都在,希望讀者可以看懂。
以上這篇Vuex,iView UI面包屑導(dǎo)航使用擴(kuò)展詳解就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
jdk1.8+vue elementui實(shí)現(xiàn)多級(jí)菜單功能
這篇文章主要介紹了jdk1.8+vue elementui實(shí)現(xiàn)多級(jí)菜單功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-09-09Vue動(dòng)態(tài)加載圖片在跨域時(shí)無法顯示的問題及解決方法
這篇文章主要介紹了解決VUE動(dòng)態(tài)加載圖片在跨域時(shí)無法顯示的問題,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03vue中實(shí)現(xiàn)動(dòng)態(tài)生成二維碼的方法
這篇文章主要介紹了vue中實(shí)現(xiàn)動(dòng)態(tài)生成二維碼的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-02-02Vue2.5 結(jié)合 Element UI 之 Table 和 Pagination 組件實(shí)現(xiàn)分頁功能
這篇文章主要介紹了Vue2.5 結(jié)合 Element UI 之 Table 和 Pagination 組件實(shí)現(xiàn)分頁功能,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2018-01-01移動(dòng)端調(diào)試神器vConsole使用詳解
vConsole?是框架無關(guān)的,可以在?Vue、React?或其他任何框架中使用,今天通過本文給大家介紹移動(dòng)端調(diào)試神器vConsole使用,感興趣的朋友一起看看吧2022-04-04