UNPKG

1.03 kBJavaScriptView Raw
1import { Message, MessageBox } from "element-ui";
2
3const extend = function(source, target) {
4 if (!target) {
5 return source;
6 }
7 for (var key in source) {
8 if (target[key] !== undefined) {
9 source[key] = target[key];
10 }
11 }
12 return source;
13};
14
15export default {
16 install(Vue, option) {
17 Vue.prototype.$extend = extend;
18 Vue.prototype.$error = message => Message({ type: "error", message });
19 Vue.prototype.$fail = message => Message({ type: "error", message });
20 Vue.prototype.$success = message => Message({ type: "success", message });
21 Vue.prototype.$warning = message => Message({ type: "warning", message });
22 Vue.prototype.$confirm = message =>
23 MessageBox.confirm(message, "提示", {
24 confirmButtonText: "确定",
25 cancelButtonText: "取消",
26 type: "warning"
27 });
28
29 Vue.mixin({
30 methods: {
31 $setState(key, value) {
32 this.$store.commit("setState", { key, value });
33 }
34 }
35 });
36 }
37};