el-switch dynamically binds the desired value

/ What to do if the data returned to you by the backend is not true and false or 1 and 2 dynamically bound /

<el-switch v-model="scope.row.isOpen" active-color="#13ce66" @change="SwitchChange(scope.row)" :active-value="1" :inactive-value="2"
inactive-color="#ff4949"></el-switch>

:active-value="1"/*开启时的值*/
:inactive-value="2"/*关闭时的值*/

  // 开关变化
SwitchChange(event) {
    /*点击时他会自动把你绑定的值变更,直接去请求数据就可以了*/
    var parms = {
        isOpen: event.isOpen,
        id: event.id
    }
    SonList.Openclose(parms).then(res => {
        this.$message({
            message: res.msg,
            type: 'success'
        })
        this.loading = false
        this.getdata()
    }).catch(error => {
          this.loading = false
          console.log(error)
      })
        console.log(event)
    },

Guess you like

Origin blog.csdn.net/xiaokangna/article/details/125562799