index.js文件
import promptBox from "./prompt-box.vue"
const PromptBox = {};
PromptBox.install = function(Vue,options) {
const PromptBoxInstance = Vue.extend(promptBox);
let currentPrompt;
const initInstance = ()=> {
currentPrompt = new PromptBoxInstance();
let promptBoxEl = currentPrompt.$mount().$el;
console.log('promptBoxEl',promptBoxEl);
console.log('document文件',document);
};
Vue.prototype.$promptBox = {
showPromptBox (options) {
console.log('document文件',document);
if(!currentPrompt) {
initInstance();
}
if(typeof options === 'string') {
currentPrompt.content = options;
} else if (typeof options === 'object') {
Object.assign(currentPrompt, options);
}
currentPrompt.showPromptBox();
}
};
};
export default PromptBox;
prompt-box.vue文件
<!-- 提示框 -->
<template>
<view class="prompt-box flex" v-show="isShowPromptBox">
<view class="main-box flex">
<i class="icon iconfont prompt-icon" :class="iconSrc" v-if="iconSrc"></i>
<slot></slot>
<!-- {{content}} -->
</view>
</view>
</template>
<script>
export default {
props: {
iconSrc: {
type: String,
default: ''
},
content: {
type: String,
default: ''
}
},
data() {
return {
isShowPromptBox: false
}
},
methods: {
showPromptBox() {
this.isShowPromptBox = true;
setTimeout(()=> {
this.isShowPromptBox = false;
}, 1000);
}
},
}
</script>
<style lang="less" scoped>
.flex {
display: flex;
align-items: center;
justify-content: center;
}
.prompt-box {
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
transition: all 3s ease;
.main-box {
flex-direction: column;
width: 610rpx;
height: 290rpx;
background: #3B3B3B;
border-radius: 16rpx;
padding: 0 51rpx;
box-sizing: border-box;
font-size: 34rpx;
font-family: PingFang SC;
font-weight: bold;
color: #FFFFFF;
.prompt-icon {
margin-bottom: 51rpx;
font-size: 100rpx;
font-weight: 500;
}
}
}
</style>
main.js文件中引入注册
import PromptBox from "components/prompt-box/index";
Vue.use(PromptBox);
|