我不知道为什么我无法在方法中获取反应值。
...
<div class="card">
<div class="card-contents">
<datafieldcheckbox class="filterComponents" :filtervalue="filterAll" @call-method="callfilteredproducts"></datafieldcheckbox>
</div>
</div>
....
new Vue({
el: "#app",
data() {
return {
filterAll: this.filtered(),
dataCategory : ["data"]
}
},
.....
methods: {
filtered() {
console.log("this.data", this.dataCategory) // Got undefined insted of getting value.
}
...
答案 0 :(得分:1)
调用filtered
方法时,data
尚未完全设置。 dataCategory
不可用是有道理的。相反,请在created
挂钩中调用它,数据已经可用。
export default {
data() {
return {
filterAll: null,
dataCategory: ["data"]
};
},
methods: {
filtered() {
console.log("this.data", this.dataCategory); // Got undefined insted of getting value.
}
},
created() {
this.filterAll = this.filtered();
}
};
(P.S。不确定你想要实现的目标。但这似乎不对。)