点击按钮调接口时报错,我直接在浏览器中调用接口时没有问题的。
methods: {
loginCheck: function () {
this.axios.get("/api/login/getAccount").then(response => {
console.log(response.data)
})
}
}
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-default/index.css'
import 'font-awesome/css/font-awesome.min.css'
import Mock from './mock'
import store from './vuex/store'
import Vuex from 'vuex'
import axios from 'axios'
import vueAxios from 'vue-axios'
// import VueResource from 'vue-resource'
Mock.bootstrap()
Vue.config.productionTip = false
Vue.use(ElementUI)
Vue.use(Vuex)
// Vue.use(VueResource)
// Vue.prototype.$ajax = axios
// Vue.prototype.$http = axios;
Vue.use(vueAxios, axios)
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
store,
template: '<App/>',
components: { App }
})
如果引入的是vue-resource 就不会报错,不知道是什么问题。
要
Vue.prototype.axios = axios
挂载到Vue.prototype
才能才页面中用this.axios
,另外这是什么import vueAxios from 'vue-axios'
,如果也是axios插件那就去掉,重复了,再者axios并不需要Vue.use(axios)
这也去掉,此外你的接口有没有在node设置好,如果没有也是不能用的