1.在component文件夾中創(chuàng)建組件confirm.vue
<template>
<div class="mask">
<div class="confirm-wrap">
<div class="title">確認刪除?</div>
<div class="handel">
<div class="btn">取消</div>
<div class="btn">確認</div>
</div>
</div>
</div>
</template>
<style lang="less" scoped>
.mask{
width: 100%;
height: 100%;
position: fixed;
z-index: 99;
background-color: rgba(0,0,0,0.6);
left: 0;
top: 0;
.confirm-wrap{
width: 250px;
height: 120px;
background-color: #fff;
position: absolute;
border-radius: 10px;
z-index: 1;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
.title{
text-align: center;
font-size: 14px;
margin-top: 20px;
}
.handel{
display: flex;
justify-content: space-between;
margin-top:20px;
border-top: 1px solid #eee;
.btn{
width: 100%;
text-align: center;
padding: 18px;
}
.btn:first-child{
color: #868686;
border-right: 1px solid #eee;
}
}
}
}
</style>
2.在component文件夾創(chuàng)建index.js
import Confirm from './confirm';
export default {
install(Vue){
Vue.component("my-confirm",Confirm)
// let ConfirmObj = Vue.extend(Confirm)
// Vue.prototype.$confirm = function(msg, btns){
// let ConfirmInit = new ConfirmObj().$mount(document.createElement("div"))
// console.log(ConfirmInit)
// document.body.appendChild(ConfirmInit.$el)
// ConfirmInit.msg = msg
// ConfirmInit.btns = btns
// console.log(msg, btns)
// }
}
}
3.在入口的main.js文件中如下配置:
import Confirm from './component';
Vue.use(Confirm)
4.在需要使用的組件中正常調(diào)用
<template>
<div id="bg">
<!-- <button @click="del">刪除</button> -->
<my-confirm></my-confirm>
</div>
</template>
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者