Vue "Computed" 值:常规功能有效,Stabby Arrow 失败
Vue "Computed" Value: Regular Function Works, Stabby Arrow Fails
当我这样写代码时,它起作用了:
<script>
export default {
props: ["notes"],
computed: {
hasNotes() { return this.notes && this.notes.some(x => x); }
}
};
</script>
但是当我这样写的时候,它失败了:
<script>
export default {
props: ["notes"],
computed: {
hasNotes : ()=> this.notes && this.notes.some(x => x)
}
};
</script>
...我不明白为什么。我在这里做错了什么?
我确定这是一个骗局,但是箭头函数使用词法范围 this
所以 this
并不意味着你认为它在箭头函数内部的意思。
当我这样写代码时,它起作用了:
<script>
export default {
props: ["notes"],
computed: {
hasNotes() { return this.notes && this.notes.some(x => x); }
}
};
</script>
但是当我这样写的时候,它失败了:
<script>
export default {
props: ["notes"],
computed: {
hasNotes : ()=> this.notes && this.notes.some(x => x)
}
};
</script>
...我不明白为什么。我在这里做错了什么?
我确定这是一个骗局,但是箭头函数使用词法范围 this
所以 this
并不意味着你认为它在箭头函数内部的意思。