使用npm安装vue-layer
npm install vue-layer
在main.js文件中配置
import Vue from 'vue'
import App from './App.vue'
import router from './router.js'
import ajax from './ajax'
import Loading from 'vue-loading-overlay'
import 'vue-loading-overlay/dist/vue-loading.css'
import layer from 'vue-layer'
import 'vue-layer/lib/vue-layer.css'
Vue.use(Loading);
Vue.config.productionTip = false
Vue.prototype.$ajax = ajax
Vue.prototype.$key = constKey
Vue.prototype.$layer = layer(Vue, {
msgtime: 3 //目前只有一项,即msg方法的默认消失时间,单位:秒
})
new Vue({
router,
render: h => h(App),
}).$mount('#app')
参数说明
{
type: 0, //0(信息框,默认)1(页面层)2(iframe层)3(加载层)4(tips层)
title: '信息',
content: '',
area: 'auto',
offset: 'auto',
icon: -1,
btn: '确定',
time: 0,
shade: true,//是否显示遮罩
yes: '',
cancel: '',
tips: [0,{}],//支持上右下左四个方向,通过1-4进行方向设定,可以设定tips: [1, '#c00']
tipsMore: false,//是否允许多个tips
shadeClose: true,//点击遮罩是否关闭
}
方法
layer.alert(content, [options, yes]);
// options和yes可以省略, 如果您不愿意写options,则可以直接写确定按钮的函数,即yes
// content 可以为html
layer.confirm(content, [options, yes, cancel]);
// options,yes和cancel可以省略, 如果您不愿意写options,则可以直接写确定按钮的函数,即yes,或者覆盖默认的cancel方法。PS:yes和cancel方法不能互换
//content 可以为html
layer.msg(content, [options, end]);
// options和end可以省略, 如果您不愿意写options,则可以直接写时间到期的回调即可,即end方法
// 默认msg的关闭时间为1.5秒
// content 可以为html
layer.tips(content, follow, options);
//content 可以为html
//follow对css选择器,用来定位目标
layer.iframe({
content: {
content: componentName, //传递的组件对象
parent: this,//当前的vue对象
data:{}//props
},
area:['800px','600px'],
title: 'title'
});
// data参数可认为是componentName的props,同时 该方法会自动添加一个key为layerid的值, 该值为创建层的id, 可以直接用来关闭该层
// options参数直接写到json里即可,比如title[](javascript:void(0);
layer.open(options);
layer.close(id);
layer.closeAll(type);
网友评论