修改用户信息
update(row) {
/* 利用深拷贝,否则直接赋值是浅拷贝,由于对象又是引用数据类型,form改变的同时也会改变row */
this.form = JSON.parse(JSON.stringify(row));
console.log(this.form);
this.dialogFormVisible = true;
},
/* 提交用户信息 */
async submit() {
/* 防止请求失败造成里面的代码错误,所以使用try,catch捕获异常 */
try {
let res = await usersPut(`users/${this.form.id}`, {
id: this.form.id,
email: this.form.email,
mobile: this.form.mobile,
});
let { meta } = res.data;
if (meta.status == 200) {
this.$message.success(meta.msg);
this.getTableDate();
this.dialogFormVisible = false;
} else {
this.$message.error(meta.msg);
}
} catch (err) {
this.$message.error(err);
}
}
用户删除
async del(row) {
try {
let {
data: {
meta: { msg, status },
},
} = await usersDelete("users/" + row.id);
if (status == 200) {
this.$message.success(msg);
this.getTableDate();
} else {
this.$message.error(msg);
}
} catch (err) {
this.$message.error(err);
}
登出功能
quit(){
/* 清除所有缓存 */
localStorage.clear();
setTimeout(()=>{
this.$router.push({name:'login'})
},500)
},