npm i --save layui-layer
在public下放入本地jquery.min.js文件,并在index.html文件中进行引入
<script src="<%= BASE_URL %>js/jquery.min.js"></script>
import layer from "layui-layer";
html
<template>
<el-button @click="handleAdd">打开弹窗</el-button>
<div style="width: 0; height: 0; overflow: hidden; ">
<div class="layer-mask-style test-mask">
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="测试" prop="lisApplicationId">
<el-input v-model="form.test" placeholder="请输入内容" />
</el-form-item>
</el-form>
</div>
</div>
</template>
js
export default {
name: "test",
data() {
return {
testMask: null,// 弹窗layer
// 表单参数
form: {},
// 表单校验
rules: {
test: [
{ required: true, message: '请输入内容', trigger: 'blur' }
],
},
}
},
methods: {
/** 新增按钮操作 */
handleAdd() {
let _this = this;
_this.reset();
_this.testMask= window.layer.open({
type: 1,
skin: 'layui-layer-demo', //样式类名
area: ['350px'],
title: '添加',
closeBtn: 1, //不显示关闭按钮
shadeClose: true, //开启遮罩关闭
content: $('.test-mask'),
btn: [ '确定', '取消' ],
yes:function (index, layero) {//这里也可以用btn1替代yes
//确定按钮回调
_this.submitForm();
},
btn2 : function() {
// 取消按钮回调
window.layer.close(_this.testMask);
_this.reset();
},
cancel: function(){
// 右上角关闭按钮回调
window.layer.close(_this.testMask);
_this.reset();
}
});
},
// 取消按钮
cancel() {
window.layer.close(this.testMask);
this.reset();
},
// 表单重置
reset() {
this.form = {
test: null,
};
this.resetForm("form");
},
},
}
icon的序号为1-7,代表含义分别如下。
window.layer.confirm('icon为1', {icon: 1, title:'提示'}, function (index) {
...
window.layer.msg('操作成功', {icon: 1, time: 1000});
window.layer.close(index);
}, function () {
window.layer.msg('已取消操作', {icon: 7, time: 1000});
});