• Vue-multiselect详解(Vue.js选择框解决方案)


    github地址:https://github.com/shentao/vue-multiselect

    官网链接:https://vue-multiselect.js.org/#sub-getting-started

    以下代码,可以直接建一个html文件,运行看到效果:

    运行效果:

    图片:

    直接复制粘贴会出来效果:

    <!DOCTYPE html>
    <html>
    
    <head>
      <script src="https://unpkg.com/vue@2.1.10/dist/vue.js"></script>
      <script src="https://unpkg.com/vue-multiselect@2.1.0"></script>
      <link rel="stylesheet" href="https://unpkg.com/vue-multiselect@2.1.0/dist/vue-multiselect.min.css">
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width">
      <title>JS Bin</title>
      <style>
      * {
      font-family: 'Lato', 'Avenir', sans-serif;
    }
      </style>
    </head>
    
    <body>
      <div id="app">
        <multiselect 
          v-model="value" 
          :options="options"
          :multiple="true"
          :taggable="true"
          :searchable="true"
          @tag="addLibrary"
          >
        </multiselect>
      
      </div>
      <script>
      new Vue({
        components: {
          Multiselect: window.VueMultiselect.default
        },
        data: {
          value: ['Vue-Multiselect'],
          options: ['Vue.js', 'Vue-Multiselect', 'Vuelidate','Vuelidate1','Vuelidate2']
        },
      methods: {
          addLibrary(lib) {
            this.options.push(lib)
          this.value.push(lib)
        }
      }
    }).$mount('#app')
    
      </script>
    </body>
    
    </html>

    另一种方式:

    <template>
        <div>
            <multiselect v-model="value" :options="options"></multiselect>
        </div>
    </template>
    
    <script>
        import Multiselect from 'vue-multiselect'
    
        export default {
            components: {
                Multiselect
            },
            data () {
                return {
                    value: '',
                    options: ['Select option', 'options', 'selected', 'mulitple', 'label', 'searchable', 'clearOnSelect', 'hideSelected', 'maxHeight', 'allowEmpty', 'showLabels', 'onChange', 'touched']
                }
            }
        }
    </script>
    
    <style src="../../dist/vue-multiselect.min.css"></style>

    好了,有了前面的栗子做铺垫,可以轻松的根据自己的需求去看官网的链接了:

    官网链接:https://vue-multiselect.js.org/#sub-getting-started

     注意点:一定要注意vue-multiselect的版本号,否则会报很多错误:如下图:

    cnpm install vue-multiselect@2.1.0 (注明今日实践这个版本不报错)

    cnpm install vue-multiselect@1.5.01(注明今日实践这个版本报错)

    报错页面:

  • 相关阅读:
    Vue 框架怎么实现对象和数组的监听?
    能说下 vue-router 中常用的 hash 和 history 路由模式实现原理吗?
    vue-router 路由模式有几种?
    Vue 组件间通信有哪几种方式?
    v-model 的原理?
    华硕笔记本修复
    linux下制作u盘启动盘
    virtualbox不能启动虚拟机
    ubuntu14.04建立wifi热点
    git中文文件名和中文目录显示乱码
  • 原文地址:https://www.cnblogs.com/DZzzz/p/9313497.html
Copyright © 2020-2023  润新知