el-button官方文档是这样的提示框,为何复制到组件里却是这样的报错?$confirm要做何处理?

1571910606(1).png
1571910633(1).png
<template>
<el-button type="text" @click="open">点击打开 Message Box</el-button>
</template>
<script>
export default {

methods: {
  open() {
    this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    }).then(() => {
      this.$message({
        type: 'success',
        message: '删除成功!'
      });
    }).catch(() => {
      this.$message({
        type: 'info',
        message: '已取消删除'
      });          
    });
  }
}

}
</script>

阅读 5.9k
2 个回答

如果您要分别导入元素,则应confirm改为在组件中本地导入方法。也就是说,导入MessageBox其confirm方法:
将this.$confirm修改为MessageBox.confirm

import { MessageBox } from 'element-ui'

export default {
methods: {

handleDelete(row) {
    MessageBox.confirm('此操作将永久删除该文件, 是否继续?', '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    }).then(() => {
      this.$message({
        type: 'success',
        message: '删除成功!'
      });
    }).catch(() => {
      this.$message({
        type: 'info',
        message: '已取消删除'
      });          
    });
}

}
}

你是不是按需引入了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题