废话不多说直接上代码
// 根据不同的状态显示不同的提示语,设置一个flag判断
let flag = '启动'
if (status === 1) {
flag = '禁止' // status=1,则提示启动,等于其他,提示禁止
}
this.$confirm('此操作将' + `${flag}` + '模型, 是否继续?', '提示', { // 设置动态文字flag,flag的值根据status不同而不同
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
// 调用接口
enable(this, {
id: id
}).then((response) => {
if (response.data.status === '0') { // 如果请求接口成功
this.$message.success(flag + '成功')
} else {
this.$message.error('操作失败!请稍后重试')
}
})
})
}).catch(() => { // 这个catch一定要注意写在这里,不是then()的后边
this.$message({
type: 'info',
message: '操作已取消'
})