Vue2.0
方法1.
创建js文件 参数中也可以传入方法
import { MessageBox } from 'element-ui';
export default{
install (Vue,options){
Vue.prototype.confirm = function(data){
MessageBox.confirm(data.content, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
center: true
}).then(() => {
this.$message({
type: 'success',
message: '删除成功!'
});
}).catch(() => {
this.$message({
type: 'info',
message: '已取消删除'
});
});
}
}
}
在main.js中全局注入
import global from "./utils/global";
Vue.use(global);
在用的地方
this.confirm({content:"此操作将永久删除选中文件, 是否继续?"});
方法2
写js文件
import { MessageBox } from 'element-ui';
export function confirm(data){
MessageBox.confirm(data.content, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
center: true
}).then(() => {
this.$message({
type: 'success',
message: '删除成功!'
});
}).catch(() => {
this.$message({
type: 'info',
message: '已取消删除'
});
});
}
在用的地方引用
import {confirm} from "../../utils/global"
export default {
methods:{
deleteItem(){
// this.confirm({content:"此操作将永久删除选中文件, 是否继续?"});
confirm({content:"此操作将永久删除选中文件, 是否继续?"});
},
deleteAll(){
// this.$root.aaa();
// this.aaa();
// this.confirm({content:"此操作将永久删除全部文件, 是否继续?"});
confirm({content:"此操作将永久删除全部文件, 是否继续?"});
},
}
}