search

Home  >  Q&A  >  body text

javascript - vue reports an error when using axios: Cannot read property 'protocol' of undefined!

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
高洛峰高洛峰2752 days ago3263

reply all(1)I'll reply

  • 仅有的幸福

    仅有的幸福2017-05-18 10:58:18

    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). .

    reply
    0
  • Cancelreply