您现在的位置是:网站首页> 编程资料编程资料
vue项目中使用this.$confirm解析_vue.js_
2023-05-24
519人已围观
简介 vue项目中使用this.$confirm解析_vue.js_
vue使用this.$confirm
首先在element-ui中的el-table下的el-table-column中引入插槽(相当于占位符)
编辑 删除
handleDelete(index, item) { this.$confirm("你确定要删除吗,请三思,后果自负", { confirmButtonText: "确定", cancelButtonText: "取消", type: "warning", }) .then(() => { console.log("确定了,要删除"); }) .catch(() => { console.log("放弃了"); }); },此时,需要在main.js中注册组件
import {MessageBox} from 'element-ui'; //Vue.use(MessageBox);//与其他引用不同的是,这里“不能”加Vue.use(MessageBox),不然会出现问题,达不到想要的效果 Vue.prototype.$confirm = MessageBox.confirm;vue TypeError: this.$confirm is not a function
错误
在使用element ui,采用局部引入时候,报错TypeError: this.$confirm is not a function。

因为没有在vue的实例上挂载confirm和message导致的报错
解决方案
修改element.js文件:
1.引入messageBox 插件
import {MessageBox} from ‘element-ui'2.在vue 的原型对象上挂载confirm
Vue.prototype.$confirm = MessageBox.confirm
如下图所示:

以后就可以放心的在vue中的任何文件使用this.confirm或者this.confirm或者this.message了。比如:你想用MessageBox中的confirm方法,现在可以这样用:
点击打开 Dialog 这是一段信息
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。
您可能感兴趣的文章:
相关内容
- React Native Modal 的封装与使用实例详解_React_
- vue常用组件之confirm用法及说明_vue.js_
- react使用useImperativeHandle示例详解_React_
- vue-router路由跳转问题 replace_vue.js_
- vue实现导出word文档功能实例(含多张图片)_vue.js_
- 在vue中如何引入外部less文件_vue.js_
- vue-router如何实时动态替换路由参数(地址栏参数)_vue.js_
- element-ui中el-input只输入数字(包括整数和小数)_vue.js_
- Vue Router修改query参数url参数没有变化问题及解决_vue.js_
- vue中如何防止用户频繁点击按钮详解_vue.js_
