vue插件 extend ( ) 【js控制組件】

1、引入vue

import Vue from 'vue'

2、引入組件

import alert from '../components/commons/alert/index.vue'

3、擴展vue

const alertBox = Vue.extend(alert)

4、聲明函數 傳入options

function alertBoxx (options){

5、new一個新對象

var alert = new alertBox({

6、創建el

el:document.createElement('div'),

7、添加數據

data(){

return{

Obj:{

isshow:true,

message:options.content,

btns:{

confirm:true,

cancel:true

}

}

}

},

8、添加方法

methods:{

confirm:options.callback

}

})

9、獲取body 並將元素添加到body

document.querySelector('body').appendChild(alert.$el)

 

Vue.nextTick(()=>{

alert.Obj.isshow= true

})

}

10、掛載到vue 並暴露

function install(){

Vue.prototype.$alert= alertBoxx

}

export default install

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章