vue el-table el-switch开关的使用

change事件的 $event 参数!!是开关变化的新状态值!

复制代码
<el-table-column
          prop="showIndex"
          label="首页展示"
          width="150"
        >
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.showIndex"
              active-value="1"
              inactive-value="0"
              active-text=""
              inactive-text=""
              @change="setShowHome(scope.row,$event)"
            />
          </template>
</el-table-column>
复制代码

 

 

复制代码
methods

setShowHome(row, val) {
      this.$confirm(`是否确认${val == '1' ? '开启' : '关闭'}首页显示?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async() => {
        setShowHome({ idList: [row.id], showIndex: val }).then(res => {
          if (res.code == '200') {
            this.$message({
              type: 'success',
              message: '首页显示设置成功',
              offset: 100
            })
          } else {
            this.$message({
              type: 'error',
              message: '首页显示设置失败',
              offset: 100
            })
            if (val == '0') {
              row.showIndex = '1'
            } else {
              row.showIndex = '0'
            }
          }
        })
      }).catch(() => {
        // 取消时恢复原始开关状态
        if (val == '0') {
          row.showIndex = '1'
        } else {
          row.showIndex = '0'
        }
      })
}
复制代码

 

posted @   porter_代码工作者  阅读(2602)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示