Cannot read properties of undefined (reading 'ajax')
时间: 2023-08-28 13:17:11 浏览: 191
问题的原因是将axios当做Vue的插件使用了,这是错误的做法。正确的做法是通过导入axios并将其赋值给Vue的原型属性$ajax来使用。所以你需要修改代码如下:
import Vue from 'vue'
import axios from 'axios'
import Router from 'vue-router'
import ElementUI from 'element-ui'
Vue.use(ElementUI)
Vue.prototype.$ajax = axios
这样就可以正常使用axios的ajax方法了。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [报错 Cannot read properties of undefined (reading ‘ajax‘); Cannot read property ‘ajax‘ of ...](https://blog.csdn.net/i_am_a_div/article/details/127220694)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [Vue用axios时报错:Uncaught(in promise)TypeError: Cannot read properties of undefined (reading ...](https://blog.csdn.net/yhj198927/article/details/124271512)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文