element 怎么去控制每一行的 switch 状态

怎么根据后端返回值 去控制每一行的状态? 主要是怎么控制每一行? 直接写scope.row.on 报错scope,拿不到

clipboard.png

       this.$get('/api/shop', this.getDate).then(res => {
          console.log(this.scope); //undefined     
          console.log(scope);      //scope is not defined
      }



      <el-table-column width="200%" label="状态" class="switchVal">
        <template slot-scope="scope">
          <el-switch
            @change="changeSwitch(scope.$index, scope.row)"
            v-model="scope.row.on"
            active-text="启用"
            inactive-text="">
            on-color="#00A854"
            on-text="启动"
            on-value="1"
            off-color="#F04134"
            off-text="禁止"
            off-value="0"
            >
          </el-switch>
        </template>
      </el-table-column>
      
      
      
      
   changeSwitch(index, row) {
    if (row.on) {
      this.$confirm('是否确认启用', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        row.on = true
      }).catch(() => {
        row.on = false
      });
    }else {
      this.$confirm('禁用后,该商户的前台页面将无法正常访问,是否确认禁用?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        row.on = false
      }).catch(() => {
        row.on = true
      });
    }
  },
阅读 3.5k
3 个回答

MVVM以数据为驱动,数据修改了View自然就变了。所以去改变v-model就行了

你这不是写了吗,在数据里面每一行都添加一个字段on,或者叫其他的。是一个布尔值,然后通过修改这个值还更新switch.,挥着switch的变化也能立刻更改到这个值上面

scope.row.on

现在是scope拿不到呗 和控制开关有关系么
把赋值scope的代码贴出来 怎么取的

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题