zoukankan      html  css  js  c++  java
  • VUE下拉多选

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    </head>
    <body>
    <div id="app">
    <el-form>
    <el-form-item>
    <el-select multiple collapse-tags v-model='selectedArray.arr' @change='changeSelect' @remove-tag='removeTag' placeholder='Select'>
    <el-option label='All' value='All' @click.native='selectAll'></el-option>
    <el-option v-for='(item, index) in options' :key='index' :label='item.name' :value='item.name'></el-option>
    </el-select>
    </el-form-item>
    </el-form>
    </div>
    <script>
    new Vue({
    el:"#app",
    data() {
    return {
    selectedArray: {
    arr:[]
    },
    options: [
    { name: '一一', label: 'one' },
    { name: '二二', label: 'tow' },
    { name: '三三', label: 'three' },
    { name: '四四', label: 'four' },
    { name: '五五', label: 'five' }
    ]
    }
    },
    methods: {
    selectAll() {
    if (this.selectedArray.arr.length < this.options.length) {
    this.selectedArray.arr = []
    this.options.map((item) => {
    this.selectedArray.arr.push(item.name)
    })
    this.selectedArray.arr.unshift('All')
    } else {
    this.selectedArray.arr = []
    }
    },
    changeSelect(val) {
    if (!val.includes('All') && val.length === this.options.length) {
    this.selectedArray.arr.unshift('All')
    } else if (val.includes('All') && (val.length - 1) < this.options.length) {
    this.selectedArray.arr = this.selectedArray.arr.filter((item) => {
    return item !== 'All'
    })
    }
    },
    // removeTag(val) {
    // if (val === 'All') {
    // this.selectedArray = []
    // }
    // }
    }


    })
    </script>
    </body>
    </html>
  • 相关阅读:
    Docker pull镜像过慢解决方法
    BUUCTF pwn一分题目
    SROP例题
    2020 NUPCTF pwn题目
    BJD4th pwn pi
    0RAYS元旦招新赛
    exit_hook在pwn题中的应用
    eclipse导包导不进来
    java算法题每日一练01,java入门简单算法题小练
    解决chrome无法启用印象笔记-剪藏功能
  • 原文地址:https://www.cnblogs.com/914556495wxkj/p/14099188.html
Copyright © 2011-2022 走看看