您当前的位置: 首页 > 

梁云亮

暂无认证

  • 2浏览

    0关注

    1211博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Vue TypeError: this.$confirm is not a function

梁云亮 发布时间:2020-11-23 09:01:45 ,浏览量:2

错误

在使用element ui,采用局部引入时候,报错TypeError: this.$confirm is not a function在这里插入图片描述 因为没有在vue的实例上挂载 c o n f i r m 和 confirm和 confirm和message导致的报错

解决方案

修改element.js文件: 1 引入messageBox 插件

import {MessageBox} from ‘element-ui’

2 在vue 的原型对象上挂载confirm

Vue.prototype.$confirm = MessageBox.confirm

如下图所示: 在这里插入图片描述 以后就可以放心的在vue中的任何文件使用this. c o n f i r m 或 者 t h i s . confirm或者this. confirm或者this.message了。比如:你想用MessageBox中的confirm方法,现在可以这样用:


  
    点击打开 Dialog
    
      这是一段信息
      
    取 消
    确 定
  
    
  


  export default {
    data () {
      return {
        dialogVisible: false
      }
    },
    methods: {
      handleClose (done) {
        const _this = this
        _this.$confirm('确认关闭?')
          .then(_ => {
            done()
          })
          .catch(_ => {
          })
      }
    }
  }

关注
打赏
1665409997
查看更多评论
立即登录/注册

微信扫码登录

0.1800s