浏览器报错:Uncaught (in promise) TypeError: Cannot read property ‘protocol‘ of undefined
报错的代码如下所示:import axios from 'axios'import VueAxios from 'vue-axios'Vue.use(axios,VueAxios)我们可以这样,加入语句:Vue.prototype.$axios=axiosimport axios from 'axios'import VueAxios from 'vue-axios'Vue.prototype.$
·
报错的代码如下所示:
import axios from 'axios'
import VueAxios from 'vue-axios'
Vue.use(axios,VueAxios)
我们可以这样,加入语句:
Vue.prototype.$axios=axios
import axios from 'axios'
import VueAxios from 'vue-axios'
Vue.prototype.$axios=axios
Vue.use(axios,VueAxios)
但还是会报“Uncaught (in promise) TypeError: Cannot read property 'protocol' of undefined”错误,那我们去掉Vue.use(axios)不就行了吗?如下所示:
import axios from 'axios'
import VueAxios from 'vue-axios'
Vue.prototype.$axios=axios
Vue.use(VueAxios)
但结果是会报下面的错误:
最终正确的避免上述报错的方式是连“Vue.use(VueAxios)”都去掉,只使用这一条语句“Vue.prototype.$axios=axios”,:
import axios from 'axios'
import VueAxios from 'vue-axios'
Vue.prototype.$axios=axios
更多推荐
已为社区贡献1条内容
所有评论(0)