A few notes about Vue Element assembly el-checkbox is checked by default and el-select value

el-select

Example:
Here Insert Picture Description

Code:

          <el-select v-model="doc.zhic" placeholder="请选择">
            <el-option
              v-for="(item,index) in zhicdata"
              :key="index"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
   doc: {
        zhic: ""
   },
   zhicdata: [
        {
          name: "主任医师",
          id: "11"
        },
        {
          name: "副主任医师",
          id: "12"
        },
        {
          name: "主治医师",
          id: "13"
        },
        {
          name: "住院医师",
          id: "14"
        }
      ],
  // 获取职称
    stepDoc(index){
      this.idx=index;
      const item = this.hislist[index];
      this.doc={
        zhic:item.zhic.toString() //获取到的是数字,一定要转换为字符串
      },
    },

v-modelValue is the value selected by default, must pay attention to here is :valuethe type must be used with v-modeltypes. Is empty, the default value is a null value.

el-checkbox

Example:
Here Insert Picture Description
Code:

          <el-checkbox-group v-model="doc.doctime">
            <el-checkbox
              v-for="item in doctimeData"
              :label="item.id"
              true-label
              :key="item.id"
              @change="changeDoctime(item.value)"
            >{{item.title}}</el-checkbox>
          </el-checkbox-group>
     doc: {
        doctime: []
      },
    doctimeData: [
        {
          value: "a1",
          title: "周一上午",
          id: 0
        },
        {
          value: "a2",
          title: "周一下午",
          id: 1
        },
        {
          value: "a3",
          title: "周一晚上",
          id: 2
        },
        {
          value: "b1",
          title: "周二上午",
          id: 3
        },
        {
          value: "b2",
          title: "周二中午",
          id: 4
        },
        {
          value: "b3",
          title: "周二下午",
          id: 5
        },
        {
          value: "c1",
          title: "周三上午",
          id: 6
        },
        {
          value: "c2",
          title: "周三下午",
          id: 7
        },
        {
          value: "c3",
          title: "周三晚上",
          id: 8
        },
        {
          value: "d1",
          title: "周四上午",
          id: 9
        },
        {
          value: "d2",
          title: "周四下午",
          id: 10
        },
        {
          value: "d3",
          title: "周四晚上",
          id: 11
        },
        {
          value: "e1",
          title: "周五上午",
          id: 12
        },
        {
          value: "e2",
          title: "周五下午",
          id: 13
        },
        {
          value: "e3",
          title: "周五晚上",
          id: 14
        },
        {
          value: "f1",
          title: "周六上午",
          id: 15
        },
        {
          value: "f2",
          title: "周六下午",
          id: 16
        },
        {
          value: "f3",
          title: "周六晚上",
          id: 17
        },
        {
          value: "g1",
          title: "周日上午",
          id: 18
        },
        {
          value: "g2",
          title: "周日下午",
          id: 19
        },
        {
          value: "g3",
          title: "周日晚上",
          id: 20
        }
      ],
      indexzc:{
        'a1':0,
        'a2':1,
        'a3':2,
        'b1':3,
        'b2':4,
        'b3':5,
        'c1':6,
        'c2':7,
        'c3':8,
        'd1':9,
        'd2':10,
        'd3':11,
        'e1':12,
        'e2':13,
        'e3':14,
        'f1':15,
        'f2':16,
        'f3':17,
        'g1':18,
        'g2':19,
        'g3':20,
      }
    // 获取医生坐诊时间
    stepDoc(index){
      this.idx=index;
      let arr = [];
      const item = this.hislist[index];
      this.dochisarr=item.zzsj.split(',')
      item.zzsj.split(',').forEach((val)=>{
        arr.push(this.indexzc[val])
        })
       this.doc={
        doctime: arr
      }
    },

v-modelThe type of the value is an array , it can be ['item1', 'item2']the value of the array is selected by default values. Can also be [1,2,3]an array of value is the array of data (as I above doctimeData) index selected by default. I get to be here because doctimeData的value属性, so I created a indexzc对象. Each cycle to push 空数组arrin.

Published 160 original articles · won praise 280 · Views 1.68 million +

Guess you like

Origin blog.csdn.net/qq_39045645/article/details/103885991