# main.js 相关
import Vue from 'vue'
import 'normalize.css/normalize.css' // 根式化css
import ElementUI, { Message } from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import locale from 'element-ui/lib/locale/lang/zh-CN'
import '@/styles/index.scss' // 全局样式
import '@/styles/element-variables.scss' // 主题
import { loading } from '@/utils/element-ui.js' // element-ui 组件全局覆盖
import App from './App.vue'
import router from './router'
import store from './store'
import './icons'
import './permission' // 路由守卫导航
import './directive' // 全局指令引入
import * as filters from './filters'
Vue.use(ElementUI, { locale })
Vue.config.productionTip = false // 生产环境关闭提示
// 全局过滤器
Object.keys(filters).forEach(key => {
Vue.filter(key, filters[key])
})
new Vue({
router,
store,
render: h => h(App)
}).$mount('#app')
// 全局对象注入
Vue.prototype.$loading = loading
// 全局重写 element 的message 弹框事件 --- 系统同时只能存在一个
Vue.prototype.$message = function(msg) {
Message.closeAll()
Message(msg)
}
const messageArr = ['success', 'warning', 'info', 'error']
messageArr.forEach(function(type) {
Vue.prototype.$message[type] = function(options) {
Message.closeAll()
return ElementUI.Message[type](options)
}
})
Vue.prototype.$message.close = function(id, userOnClose) {
return ElementUI.Message.close(id, userOnClose)
}
Vue.prototype.$message.closeAll = function() {
return ElementUI.Message.closeAll()
}