Vue自定义组件(模仿iOS UIAlertActionController)

1.在component文件夹中创建组件confirm.vue

 




2.在component文件夹创建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.在需要使用的组件中正常调用






自定义组件

你可能感兴趣的:(Vue自定义组件(模仿iOS UIAlertActionController))