ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

在vue中编写用户列表的查询和删除功能

2021-12-12 21:33:35  阅读:57  来源: 互联网

标签:vue resp vm 查询 scope 列表 data id row


查询、删除代码如下;

<template>
  <div class="login-box">
    <el-table :data="tableData"  border>
      <el-table-column align="center" label="id"  width="140">
        <template v-slot="scope">
          {{scope.row.id}}
        </template>
      </el-table-column>
      <el-table-column align="center" label="姓名"  width="140">
        <template v-slot="scope">
          {{scope.row.uname}}
        </template>
      </el-table-column>

      <el-table-column align="center" label="密码"  width="140">
        <template v-slot="scope">
          {{scope.row.pwd}}
        </template>
      </el-table-column>

      <el-table-column align="center" label="邮箱" width="140">
        <template v-slot="scope">
          {{scope.row.email}}
        </template>
      </el-table-column>

      <el-table-column align="center" label="电话号码"  width="140">
        <template v-slot="scope">
          {{scope.row.phone}}
        </template>
      </el-table-column>

      <el-table-column  label="Actions" align="center"  width="230" class-name="small-padding  fixed-width">
        <template v-slot="scope">
          <el-button type="primary" size="mini">
            编辑
          </el-button>
          <el-button type="mini" size="danger" @click="deluser(scope.row.id)">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
    export default {
        name: "user-lists",
      data(){
          return{
            tableData:[]
          }
      },
      created(){
          this.fetchData()
      },
      methods:{
        fetchData(){
          var vm=this;
          this.$axios({
            method:'get',
            url:'http://localhost:8080/user/selectUserList'
          }).then(function (resp) {
            vm.tableData=resp.data;
          });

        },
        deluser(id){
          var vm=this;
          this.$axios({
            method:'GET',
            url:'http://localhost:8080/user/deleteUser?id='+id

          }).then(function (resp) {
           /* vm.tableData=resp.data*/
           console.log(resp.data);
           if(resp.data=="success"){
             vm.$message({
               message:'删除成功',
               type:'success'
             });
           /*  vm.$router.push("/UserLists")*/
             vm.fetchData();//更新数据
           }
          }).catch(function (error) {
            vm.$message.error('错了');
          });
        }
      }
    }
</script>

<style scoped>

</style>

 

标签:vue,resp,vm,查询,scope,列表,data,id,row
来源: https://www.cnblogs.com/wyxjava/p/15680596.html

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有