我有select:
<select @change="getValuesFromDate($event)">
<option value="1">Last 24 hours</option>
<option value="7">Last7 days</option>
<option value="30">Last 30 days</option>
<option>Custom date</option>
</select>
Run Code Online (Sandbox Code Playgroud)
和图表组件
<graph-component
:key="graphKey"
v-bind="measurement"
:value="valueOfMeasurement(measurement)"
:time_date="dateOfMeasurement()"
></graph-component>
Run Code Online (Sandbox Code Playgroud)
函数getValuesFromDate($event)调用API:
getValuesFromDate(event) {
let apiLink ="https://api.thingspeak.com/channels/1111111/feeds.json?api_key=XXXXXXXXXXXX&days=" +event.target.value +"&round=2&average=";
let preferableSize = 0;
if (event.target.value == 1) {
preferableSize = 60;
} else {
preferableSize = 1440;
}
try {
axios
.get(apiLink + preferableSize, {
withCredentials: false
})
.then(response => {
this.message = response.data;
});
this.graphKey+= 1;
} catch (error) {}
}
Run Code Online (Sandbox Code Playgroud)
当我更改选择(并调用此函数)时,我通过更改它的键来重新渲染graph-component,并且它工作得很好。什么是更好、更正确的方法来做到这一点,或者这个方法足够好?
| 归档时间: |
|
| 查看次数: |
1693 次 |
| 最近记录: |