Переглянути джерело

this.$message.info() 的默认显示时长是 3s, 在 main.js 中修改显示时长为 1s

reghao 3 днів тому
батько
коміт
74ae193a28
1 змінених файлів з 27 додано та 0 видалено
  1. 27 0
      src/main.js

+ 27 - 0
src/main.js

@@ -36,6 +36,33 @@ Vue.prototype.$echarts = echarts
 
 
 import '@/permission'
 import '@/permission'
 
 
+// 全局配置 Message 的默认 duration 为 5000 毫秒(5秒)
+Vue.use(ElementUI, {
+  size: 'small',
+  zIndex: 3000
+})
+
+// 单独为 Message 修改原型上的默认属性
+Vue.prototype.$message = function(options) {
+  if (typeof options === 'string') {
+    options = { message: options }
+  }
+  // 默认加入 duration: 5000,如果传入了新值则覆盖默认值
+  options.duration = options.duration === undefined ? 1000 : options.duration
+  return ElementUI.Message(options)
+};
+
+// 挂载快捷方法(如 .warning, .success 等)
+['success', 'warning', 'info', 'error'].forEach(type => {
+  Vue.prototype.$message[type] = function(options) {
+    if (typeof options === 'string') {
+      options = { message: options }
+    }
+    options.type = type
+    return Vue.prototype.$message(options)
+  }
+})
+
 Vue.config.productionTip = false // 阻止控制台打印生产模式下的消息
 Vue.config.productionTip = false // 阻止控制台打印生产模式下的消息
 Vue.prototype.baseURL = process.env.VUE_APP_SERVER_URL
 Vue.prototype.baseURL = process.env.VUE_APP_SERVER_URL
 new Vue({
 new Vue({