美文网首页
vue基于element 封装一个自己的组件

vue基于element 封装一个自己的组件

作者: 上海老宅男 | 来源:发表于2020-06-12 22:41 被阅读0次

在components里面新建一个js

import Vue from 'vue'
//确定窗
Vue.prototype.$JcMsgBox = function alert(msg = '确认要删除该数据?' ,type = 'success', title = '系统提示', settings = {}) {
  Object.assign(settings, {  //合并对象
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type:type,
    dangerouslyUseHTMLString: true //允许确认框内容为html格式
  })
  return this.$confirm(`<p style="font-weight:bold;">${msg}</p>`, title, settings)
}

在main.js里面引入实例

import './components/global/JcMsgBox'

使用的时候直接在页面调用

this.$JcMsgBox('提示语句','类型图标','弹窗标题')
 .then(res => {
console.log('点击确定执行的方法')
 })
 .catch(errMsg => {
          this.$alert(errMsg, { type: 'error' })
 })

相关文章

网友评论

      本文标题:vue基于element 封装一个自己的组件

      本文链接:https://www.haomeiwen.com/subject/vzkotktx.html