Vue自定义插件-弹窗

1,422 阅读1分钟

全局组件与全局插件的区别

全局组件的使用方式:

<VNavbar></VNavbar>

全局插件的使用方式:

methods: {
    showMsgbox (){
        this.$msgbox({
            type: 'warning',
            title: '温馨提示',
            cancel: '取消',
            content: '这里可以放置HTML',
            confirm: '确定',
            className: 'pop-custom'
        }).then(() => {
            console.log("我点击了确定按钮")
        }).catch((err) => {
            console.log("error")
        })
    }
}

1. 在src/components 目录新建 msgbox 目录

在 msgbox 目录,新建 msgbox.vue 组件。

msgbox.vue:

<template>
    <div>
        <transition name="msgbox">
            
        </transition>
        <div class="msgbox-mask" v-show="isShowMask"></div>
    </div>
</template>

参考

vue自定义插件-弹框

源码地址 github.com/zuobaiquan/…