[英]Can't pass data from model to method in Vue.js
I have a graph with a simple dropdown list with years and I need to pass the year whenever it's modified by the user so the graph will show that year's data.我有一个带有年份的简单下拉列表的图表,我需要在用户修改年份时传递年份,以便图表显示当年的数据。
For example, when I try to access the parameters from this method all i get is undefined:例如,当我尝试从这个方法访问参数时,我得到的都是未定义的:
fetchBarChartData({ anio, sort }) {
var self = this;
console.log(anio);
fetch("https://demo8358110.mockable.io/year/" + this.anio) // insert your api call here
.then(function(response) {
var r = response.json();
return r;
})
.then(function(data) {
self.values = data.values;
self.valuesline = data.valuesline;
self.loaded = true;
});
https://demo8358110.mockable.io/year/undefined https://demo8358110.mockable.io/year/undefined
EDIT: I've added an example https://codesandbox.io/s/vue-template-x4z7b编辑:我添加了一个示例https://codesandbox.io/s/vue-template-x4z7b
您需要将更改的年份传递给您的 fetchBarChartData 函数:
<select name="year" v-model="year" @change="fetchBarChartData(year)">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.