async getData() { const {data:ret} = await this.$http.get('yearCount') this.allData = ret // console.log(ret); this.updataChart() }, updataChart() { const sellerValues = this.allData.map((item) => { return item.value }) const sellerNames = this.allData.map((item) => { return item.name })报错chart1.vue:64 Uncaught (in promise) TypeError: this.allData.map is not a function,怎么解决?
时间: 2023-07-16 12:14:11 浏览: 52
这个错误的原因是 `this.allData` 不是一个数组,而是一个 undefined 或者其他类型的值。你可以在调用 `updataChart()` 方法之前,先确保 `this.allData` 已经被赋值为一个正确的数组。或者在 `updataChart()` 方法中,先进行一个类型判断,避免在非数组类型上调用 `map()` 方法。例如:
```
updataChart() {
if (!Array.isArray(this.allData)) {
console.error('this.allData is not an array')
return
}
const sellerValues = this.allData.map((item) => {
return item.value
})
const sellerNames = this.allData.map((item) => {
return item.name
})
// ...
}
```
相关问题
async Search(){ const{ res } = await this.$http.get('music/search',this.input) this.musiclist = res
根据您提供的代码来看,似乎并没有设置 "search" 参数的值。您可以将参数添加到 `this.input` 对象中,例如:
```
this.input = {
search: 'your search keyword'
}
```
另外,如果您使用的是后端框架如 Spring MVC,还需要在后端对应的方法参数中添加 `@RequestParam` 注解来获取请求参数。
希望这些信息对您有所帮助。
// async getLogin() { // if (this.login()) { // const data = await this.$axios.post( // "/tax/wechat/login", // { // mobile: this.form.phoneNumber, // code: this.form.idNumber, // } // ); // if (data.success) { // this.$router.push("/myInfo"); // } else { // this.$router.push("/authentication"); // } // } // },从这个接口中获取response Headers 里Ssessionid的值,并存放到sessionStorage里
你可以通过访问响应的`headers`属性来获取`Session-Id`的值,并将其存放在`sessionStorage`中。以下是一个示例代码:
```javascript
async getLogin() {
if (this.login()) {
const response = await this.$axios.post("/tax/wechat/login", {
mobile: this.form.phoneNumber,
code: this.form.idNumber,
});
// 获取Session-Id
const sessionId = response.headers['session-id'];
// 将Session-Id存放在sessionStorage中
sessionStorage.setItem('sessionId', sessionId);
if (data.success) {
this.$router.push("/myInfo");
} else {
this.$router.push("/authentication");
}
}
},
```
请注意,示例中的`this.$axios.post`是一个假设的请求方法,你需要根据实际情况使用你的网络请求库进行替换。另外,这里假设后端在响应头中将会话id存放在`session-id`字段中,你需要根据实际情况进行调整。在之后的请求中,你可以使用存储在`sessionStorage`中的会话id来设置请求头。