Home > Web Front-end > JS Tutorial > body text

Using vue2.0.js to implement multi-level linkage selectors

亚连
Release: 2018-06-06 15:31:19
Original
2945 people have browsed it

Now I will share with you an implementation method of multi-level linkage selector in vue2.0.js, which has a good reference value and I hope it will be helpful to everyone.

Due to work requirements, I want to implement a multi-level linkage selector, but none of the existing linkage selectors on the Internet is what I want. I refer to the Cascader cascade selection in element-ui based on vue2.0 The style of the selector implements the multi-level linkage selector that combines your own requirements. The principle is very simple. I won’t go into details and just go to the code. . .

<template>
 <p id="app">
 <p class="select">
  <p class="input_text"><input type="text" name="" v-on:focus="options1Show" v-model="result"></p>
  <p class="options1" v-show="options1isShow">
  <ul>
   <li v-on:click="toClick(option.value)" v-for="option in options">{{option.label}}</li>
  </ul>
  </p>
  <p class="options2" v-show="options2isShow">
  <ul >
   <li v-for="item in secondOptions" v-on:click="selectResult(item.label,item.value)">{{item.label}}</li>
  </ul>
  </p>
 </p>
 </p>
</template>
<script>
export default {
 name: &#39;app&#39;,
 data(){
 return {
  options:[
  {
   value:&#39;zhinan&#39;,
   label:&#39;指南&#39;,
   children:[
   {
    value: &#39;yizhi&#39;,
    label: &#39;一致&#39;
   }, {
    value: &#39;fankui&#39;,
    label: &#39;反馈&#39;
   }, {
    value: &#39;xiaolv&#39;,
    label: &#39;效率&#39;
   }, {
    value: &#39;kekong&#39;,
    label: &#39;可控&#39;
   }
   ]
  },
  {
   value: &#39;daohang&#39;,
   label: &#39;导航&#39;,
   children: [{
   value: &#39;cexiangdaohang&#39;,
   label: &#39;侧向导航&#39;
   }, 
   {
   value: &#39;dingbudaohang&#39;,
   label: &#39;顶部导航&#39;
   }]
  }
  ],
  secondOptions:[],
  options1isShow:false,
  options2isShow:false,
  result:&#39;&#39;
 }
 },
 methods:{
 options1Show:function(){
  this.options1isShow=true;
 },
 toClick:function(item){
  this.secondOptions=[];
  for(var i=0;i<this.options.length;i++){
  if(this.options[i].value==item){
   console.log(this.options[i].children);
   this.secondOptions=this.options[i].children;
   console.log(this.secondOptions);
  }
  }
  this.options2isShow=true;
 },
 selectResult:function(label){
  this.result=label;
  this.options1isShow=false;
  this.options2isShow=false;
 }
 }
}
</script>
<style>
li,ul{
 list-style: none;
 padding:0;
 margin:0;
}
li{
 height:40px;
 line-height: 40px;
 border-bottom: 1px solid #ededed;
 box-sizing: border-box;
 text-align: center;
 cursor: pointer;
}
.select{
 position: relative;
}
.input_text>input{
 width:170px;
 height:30px;
 border:1px solid #ddd;
}
.options1,.options2{
 width:170px;
 height:200px;
 border:1px solid #ddd;
 position: absolute;
 background: #fff;
 overflow-y: auto;
}
.options2{
 left:170px;
}
</style>
Copy after login

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Use the select drop-down box to implement binding and value methods in vue.js

Through vue in v -How to implement that the first one is checked by default in the for loop checkbox?

How to implement value-passing and URL encoding conversion in JS forms?

The above is the detailed content of Using vue2.0.js to implement multi-level linkage selectors. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!