Vue在单独引入js文件中使用ElementUI的组件
问题场景:
我想在vue中的js文件中使用elementUI中的组件,因为我在main.js中引入了element包和它的css,并挂载到了全局vue实例中。然后我就在js文件中这样使用
this.$notify({
title: "失败",
message: "请先登录老铁~",
type: "error"
});
结果报错了,报错信息如下
TypeError: _this.$notify is not a function
at index.js:44
2019-03-26更新
import axios from 'axios'
// 注意:在js文件中使用element组件 按照下面更优雅哦~~
import {
Message,
MessageBox
} from 'element-ui'
import store from '../store'
import {
getToken
} from '@/utils/auth'
// 创建axios实例
const service = axios.create({
baseURL: process.env.BASE_API, // api 的 base_url
timeout: 5000 // 请求超时时间
})
// request拦截器