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
<br />Question: How to write in HTML to jump...
1. First create the file (cd to the directory whe...
Select the category selection. After testing, IE ...
Table of contents Environmental Description Docke...
In the front-end layout process, it is relatively...
mysql5.6.28 installation and configuration method...
The most common, most commonly used and most gener...
In this tutorial, we use the latest MySQL communi...
Disclaimer: This password reset method can direct...
Table of contents Rendering Install Code Implemen...
Find the problem Recently, when I was filling in ...
Using ajax to implement form submission without re...
question After the company migrated the server, t...
This article uses examples to illustrate the prin...
CSS adds scrolling to div and hides the scroll ba...