Vue+iview menu and tab linkageI am currently developing a backend management system using vue+iview. I hope to make a corresponding change to the tab and content on the right side of the left menu when I click on it. But after working on the routing for a long time, I still haven't achieved this function. When I first started using vue+iview, I didn’t know that iview-admin could be used directly, and the layout and other things were ready to use out of the box. However, I had already written my demo for a long time and couldn’t bear to give up. 1. Use iview's menu and tab for layout and place these two components on the main pageSince the data of menu and tab are the same and the styles need to be associated, vuex can be used for state management. The data and state variables that need to be managed are written in state, the operation actions are set in mutations, and some behaviors are listened in actions (my menu does not have expansion and contraction parts, so actions are not used) 2. After the layout is completed, click events should be added to the menuon-select, first register the tab change event in mutations. When the left menu is clicked, check whether there is already a tab in the tab and set isExist=false. If it exists, isExist is changed to true. If not, add the menu relative index data to the array traversed by the tab. mutationsType In mutations: The events in the menu component are: First set the default route of the page in the tab component: Then add the event: iview+Vue multi-level menu linkageI wrote a three-level menu linkage in the dumbest way possible. <template> <div> <Select v-model="whereMap.model1" style="width:200px" @on-change="getSecond"> <Option v-for="item in list1" :value="item.id" :key="item.id">{{ item.label }}</Option> </Select> <Select v-model="whereMap.model2" style="width:200px" @on-change="getThird"> <Option v-for="item in list2" :value="item.id" :key="item.id">{{ item.label }}</Option> </Select> <Select v-model="whereMap.model3" style="width:200px"> <Option v-for="item in list3" :value="item.id" :key="item.id">{{ item.label }}</Option> </Select> <Button class="search-btn" type="default" @click="searchClear">Clear</Button></div> </template> <script> export default { data () { return { datatest: { l1: [ { id: 'cat', label: 'cat' }, { id: 'dog', label: 'dog' } ], l2: { cat: [{ id: 'sc', label: 'Kitten' }, { id: 'bc', label: 'Big cat' }], dog: [{ id: 'sd', label: 'Puppy' }, { id: 'bd', label: 'Big dog' }] }, l3: { sc: [{ id: 'sc1', label: 'Little cat' }, { id: 'sc2', label: 'Little orange cat' }], bc: [{ id: 'bc1', label: 'Big tabby cat' }, { id: 'bc2', label: 'Big orange cat' }] } }, list1: [], list2: [], list3: [], whereMap: { model1: '', model2: '', model3: '' } } }, mounted () { this.init() }, created () { this.init() }, methods: { init () { this.list1 = this.datatest.l1 }, getSecond(val) { this.list2 = this.datatest.l2[val] }, getThird (val) { this.list3 = this.datatest.l3[val] }, searchClear () { console.log(this.whereMap) this.whereMap = {}; this.list2 = []; this.list3 = []; } } } </script> The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. You may also be interested in:
|
<<: HeidiSQL tool to export and import MySQL data
This article shares the MySQL Workbench installat...
Table of contents Diffing Algorithm Layer-by-laye...
Shtml and asp are similar. In files named shtml, s...
1. Install mutt sudo apt-get install mutt 2. Inst...
Nginx supports three ways to configure virtual ho...
1. Problem Description Today I need to check the ...
The first step is to check the version number and...
Preface This article mainly introduces the releva...
Copy code The code is as follows: <!DOCTYPE ht...
Editor: This article discusses the role that inte...
Database stored procedures DROP PROCEDURE IF EXIS...
Purpose: Under Linux, the server program may be d...
Table of contents 1. Function Binding 2. With par...
1. JS asynchronous execution principle We know th...
I have encountered the Nginx 502 Bad Gateway erro...