【发布时间】:2020-08-19 17:28:54
【问题描述】:
如何将axios中的数据放到vue js数据中:value: [parseInt(this.maintemp1),parseInt( this.maintemp2)], <--------Here is my problem
export default {
data: () => ({
maincity: "",
maintemp1: "",
maintemp2: "",
maindate1: "",
showLabels: true,
lineWidth: 2,
labelSize: 7,
radius: 10,
padding: 8,
lineCap: "round",
gradient: gradients[5],
value: [parseInt(this.maintemp1),parseInt( this.maintemp2)], <--------Here is my problem
gradientDirection: "top",
gradients,
fill: true,
type: "trend",
autoLineWidth: false
}),
mounted() {
axios
.get(
"http://api.openweathermap.org/data/2.5/forecast?q=khiva&units=metric&appid=myapi"
)
.then(response => {
this.wholeResponse = response.data.Search;
this.maincity = response.data.city.name;
this.maindate1 = response.data.list[1].dt_txt;
this.maintemp1 = response.data.list[1].main.temp;
this.maintemp2 = response.data.list[9].main.temp;
})
.catch(error => {
console.log(error);
});
}
};
【问题讨论】:
-
因为它依赖于其他数据属性,所以将
value设为computed属性。value: [parseInt(this.maintemp1),parseInt( this.maintemp2)],不锁定函数,而是 data() 中的值 -
在答案中添加了代码更改示例
标签: javascript arrays vue.js axios vuetify.js