【大坑】使用element-ui弹窗$confirm自动弹出
插入element-ui的弹窗后页面一刷新自动弹出,事件绑定、调用位置(生命周期)均没有问题,通过不断注释组件发现是main.js全局引入导致的问题。如果需要在某些组件中使用三方弹窗,可以按需引入
,而不是全局注册
import { MessageBox } from 'element-ui';
// 在组件中使用
MessageBox.confirm('确认操作吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
console.log('用户点击了确定');
}).catch(() => {
console.log('用户点击了取消');
});