zoukankan      html  css  js  c++  java
  • el-switch的使用

    基础使用参考官网

    这篇文章记录更改用户状态,如果操作失败,回到操作前的状态的方法

    change事件监听用户操作

    代码

    <template>
        <el-table :data="tabelData" border>
          <el-table-column prop="id" label="编号"></el-table-column>
          <el-table-column prop="username" label="姓名"></el-table-column>
          <el-table-column label="状态">
            <template slot-scope="scope">
              <!-- {{scope.row}} -->
              <el-switch v-model="scope.row.status" @change="changeUserStatus(scope.row)"></el-switch>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </template>
    
    <script>
      export default{
        name:"Custom",
        data(){
          return{
            tabelData:[
              {username:"Ann",id:1,status:true},
              {username:"Linda",id:2,status:false},
              {username:"July",id:3,status:true}
            ]
          }
        },
        methods:{
         async changeUserStatus(userinfo){
            console.log(userinfo)     
         await  let {data:res}=this.$http.put(`/update/${userinfo.id}/status/${userinfo.status}`)//使用了es6中的对象解析和字符串模板
          }
            if(res.code!=200){
          userinfo.status=!userinfo.status;
          }
        }
      }
    </script>
    
    
                
  • 相关阅读:
    form表格属性
    sql查询练习题
    在Mac上搭建java开发环境
    搭建vim作为java开发环境(-)
    C++学习之class
    nginx学习----1
    Html5学习笔记---1
    国庆节
    memcache------01
    jquery学习之概述
  • 原文地址:https://www.cnblogs.com/shanchui/p/14418737.html
Copyright © 2011-2022 走看看