axios.post().then(function(resp)中ImportOne.vue:74 Uncaught (in promise) TypeError: Cannot read properties of undefined
时间: 2023-11-23 07:56:30 浏览: 103
这个错误通常是由于this指向不正确导致的。在axios.post().then(function(resp)中,this指向的是回调函数本身,而不是Vue实例。因此,当你尝试访问Vue实例中的数据时,会出现“Cannot read properties of undefined”错误。为了解决这个问题,你可以使用箭头函数或将this存储在变量中,以便在回调函数中使用它。以下是两种解决方法:
1.使用箭头函数
```javascript
this.axios({
method: 'post',
params: {
yhm: this.yhm,
pwd: this.pwd
},
url: 'http://localhost:1111/01/zhuce'
}).then((resp) => {
console.log(resp.data);
this.mes = resp.data;
})
```
2.将this存储在变量中
```javascript
var vm = this;
this.axios({
method: 'post',
params: {
yhm: this.yhm,
pwd: this.pwd
},
url: 'http://localhost:1111/01/zhuce'
}).then(function(resp) {
console.log(resp.data);
vm.mes = resp.data;
})
```
相关问题
login.vue:23 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '$axios')
这个错误是因为在login.vue文件的第23行,代码尝试读取$axios属性,但是$axios属性未定义。这可能是因为没有正确地将axios添加到Vue实例中。正确的方法是在main.js文件中导入axios并将其添加到Vue.prototype中,如下所示:
```javascript
import axios from "axios";
Vue.prototype.axios = axios;
```
这样就可以在组件中使用`this.axios`来访问axios实例了。请确保在login.vue文件中使用了`this.axios`而不是`$axios`。
index.vue:594 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'stSoftwareResultEntityList')
根据引用中的报错信息,index.vue文件的第594行出现了一个未捕获的错误。具体错误信息是"TypeError: Cannot read properties of undefined (reading 'stSoftwareResultEntityList')"。根据引用中的代码,这个错误可能是因为获取数据时发生了一些问题。在获取数据的函数中,如果返回的数据为undefined,就会将一个新对象赋值给info.value。因此,可能需要检查数据获取的部分代码,确保正确处理数据的返回情况。此外,根据引用的内容,还可以在axios请求拦截器中进行一些配置,以便更好地处理请求和错误。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![js](https://img-home.csdnimg.cn/images/20250102104920.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)