• 解决el-checked-group中v-medel绑定的是一个数组对象方法(不用修改源码)


    思路:弃用el-checked-group使用el-checked模拟

    <!DOCTYPE html>
    <html>
    
    <head>
      <meta charset="UTF-8">
      <!-- import CSS -->
      <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
      <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vant@2.2/lib/index.css">
    </head>
    
    <body>
      <div id="app">
        <div style="margin: 15px 0;"></div>
        <div v-for="city in cities">
          <el-checkbox  :label="city" :key="city.id" :checked=indexOf(city,checkedCities) @change=change(city,indexOf(city,checkedCities)) >{{city.name}}</el-checkbox>
        </div>
        {{ result }}
      </div>
    </body>
    <!-- import Vue before Element -->
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <!-- import JavaScript -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vant@2.2/lib/vant.min.js"></script>
    <script>
      new Vue({
        el: '#app',
        data: function () {
          return {
            checkAll: false,
            result:[],
            checkedCities: [{
                name: "上海",
                id: 1
              }],
            cities: [{
                name: "上海",
                id: 1
              },
              {
                name: "北京",
                id: 2
              }
            ],
            isIndeterminate: true
          }
        },
        created(){
          this.$nextTick(() => {
            this.result = this.checkedCities
          })
        },
        methods: {
          indexOf(item, items) {
            console.log(items.indexOf(item))
            items = JSON.stringify(items)
            item = JSON.stringify(item)
            if(items.indexOf(item) > -1 ){
              return true
            }else{
              return false
            }
          },
          change(e,c){
            if(c){
              this.result.forEach((value, index, array) => {
                if (e.id == value.id) {
                  this.result.splice(index, 1)
                }
              })
            }else{
              this.result.push(e)
            }
          }
        }
      })
    </script>
    
    </html>

     

  • 相关阅读:
    AngularJs 键盘事件和鼠标事件
    Linux的net.ipv4.tcp_timestamps参数
    实战:tcp链接rst场景tcpdump分析
    C++ map使用总结
    C++ 11常见功能介绍:auto,decltype,nullptr,for,lambda
    BLOCK层基本概念:bio,request,request_queue
    C: 字符数组中的空去掉
    代码静态分析工具-splint的学习与使用[转]
    代码分析工具splint安装介绍
    gcc/g++ 如何支持c11/c++11标准编译
  • 原文地址:https://www.cnblogs.com/hy96/p/13404898.html
Copyright © 2020-2023  润新知