javascript - vue reports an error when using axios: Cannot read property 'protocol' of undefined!
高洛峰
高洛峰 2017-05-18 10:56:18
0
1
3273
import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'

Vue.use(Vuex)
Vue.use(axios)

Error message:

isURLSameOrigin.js?cf95:57 Uncaught (in promise) TypeError: Cannot
read property 'protocol' of undefined

at isURLSameOrigin (eval at <anonymous> (app.js:929), <anonymous>:57:21)
at dispatchXhrRequest (eval at <anonymous> (app.js:754), <anonymous>:108:50)
at Promise (<anonymous>)
at xhrAdapter (eval at <anonymous> (app.js:754), <anonymous>:12:10)
at dispatchRequest (eval at <anonymous> (app.js:866), <anonymous>:52:10)

Error screenshot:

But, using it in prototype mode is normal:

import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'

Vue.use(Vuex)
Vue.prototype.$ajax = axios
高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(1)
仅有的幸福

Why do some people always think that axios is a vue plug-in. . By the way, there is somewhere written for you to use Vue.use(axios). .

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template