现有需求点击按钮,需要确认是否执行,看了下element-ui的官网方法,地址如下
https://element.eleme.cn/#/zh-CN/component/message-box
<template>
<el-button type="text" @click="open">点击打开 Message Box</el-button>
</template>
<script>
export default {
methods: {
open() {
this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.$message({
type: 'success',
message: '删除成功!'
});
}).catch(() => {
this.$message({
type: 'info',
message: '已取消删除'
});
});
}
}
}
</script>
然后根据这做法写出自己的前后端交互的方法,第一次用这组件用的不怎么好,也不知道怎么写,就照猫画虎的写了一下,应该还能精简
forceUpdateDevice(){
this.$confirm('此操作将强制重置设备, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
Fetch.delete("${request.contextPath }/member/forceUpdateDevice", {
id: memberId
}).then(result => {
if (!result){
this.$message({
type: 'warning',
message: '重置失败!'
});
}else {
this.$message({
type: 'success',
message: '重置成功!'
});
}
}).catch().finally();
}).catch(() => {
this.$message({
type: 'info',
message: '已取消强制重置设备'
});
});
},
感觉很冗杂,正在想办法精简。但是效果是出来了
后台也成功的交互到了
顺便记录下进这个页面之前的layui是否显示该标签的用法或者说是语法,反正我看着是挺反感的
d就是该行的数据,是个形参
<script type="text/html" id="updateDeviceTpl">
{{# if(d.unbind == true){ }}
<input type="checkbox" name="updateDevice" value="{{d.id}}" title="解绑" lay-filter="updateDevice" {{d.unbind== true ? 'checked':'' }}></input>
{{# }if(d.unbind == false){ }}
<input type="checkbox" name="updateDevice" value="{{d.id}}" title="解绑" lay-filter="updateDevice" {{d.unbind== true ? 'checked':'' }} disabled></input>
{{# } }}
</script>