Vue从零开始开发管理系统(学习笔记第十节)

一、添加用户的方法编写

接口:users

方法:post

参数:username
        password
        email
        mobile

async addUser(){
    this.$refs.Ref.vaildate(async (vaild)=>{
        if(!vaild) return
        const{data:res}=async this.$http.post('users',this.Form)
        if(res.meta.status!==200) return this.$message.error(res.meta.msg)
        this.$message.success(res.meta.msg)
        this.getUser()
        this.isVisible=false
    })

二、修改用户功能

1.显示一个编辑用户的dialog

<el-dialog title="编辑" :visible.sync="isVisible " width="40%">
<span>
//编辑用户的表单
</span>
<span slot="footer">
    <el-button @click="isVisible = false">取 消</el-button>
    <el-button type="primary" @click="update()">确 定</el-button>
</span>
</el-dialog>

2.获取该行数据

<el-table-column label="操作" width="180px">
    <template slot-scope="scope">
        <el-tooltip effect="dark" content="修改" placement="top" :enterable="false">
            <el-button type="primary" icon="el-icon-edit" size="mini" click="editUser(scope.row)">
        </el-tooltip>
    </>
</>




<el-dialog title="编辑" :visible.sync="isVisible " width="40%">
<span>
    <el-form :model="editForm" ref="editRef" label-width="100px" :rules="editRul">
        <el-form-item><el-input v-model="editForm.username" :disabled="true"></el-input></>
        <el-form-item><el-input v-model="editForm.email"></el-input></>
        <el-form-item><el-input v-model="editForm.mobile"></el-input></>
    <el-form>
</span>
<span slot="footer">
    <el-button @click="isVisible = false">取 消</el-button>
    <el-button type="primary" @click="update()">确 定</el-button>
</span>
</el-dialog>


methods:{
    async editUser(info){
    const{data:res}=await this.$http.get('users/'+info.id)
    this.editForm=res.data
    this.isVisibleState=true
    }
}

更新

update(){
            this.$refs.editRef.validate(async(vaild)=>{
                if(!vaild) return
                const{data:res}=await this.$http.put('users/'+this.editForm.id,{email:this.editForm.email,mobile:this.editForm.mobile})
                if(res.meta.status!==200) return this.$message.error(res.meta.msg)
                this.$message.success(res.meta.msg)
                this.getUserList()
                this.isVisibleState=false


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

bigdata大星星

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值