vue工程的axios配置的axios.js中如何获取vue实例?
vue工程中,我在.vue文件中this可以获取vue对象,在.js文件中this.XX无法获取vue实例,怎么办呢,我想使用this.*方法
我想在*.js里面使用vue实例的this.$createElement 所以我这么做的
我下面这么写的,解决了我的问题,但是优雅吗?
import Vue from 'vue'
import App from './App.vue'
new Vue({
router,
store,
render: h => h(App),
created() {
Vue.prototype.$createElementNode = this.$createElement
}
}).$mount('#app')
axios.js文件里面:
import { MessageBox } from 'element-ui';
import Vue from 'vue'
const h = Vue.prototype.$createElementNode
MessageBox({
title: '消息',
// message: message,
message: h('div', null, [
h('el-input', {
props: {
value: 1234,
}
}),
h('el-input', {
props: {
value: 1234,
}
})
]),
showCancelButton: true,
confirmButtonText: '确定',
cancelButtonText: '取消'
})