Vue“ Compute”值:常规函数有效,Stabby箭头失败[重复]

问题描述 投票:0回答:1

当我编写这样的代码时,它起作用:

<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>

...,我不明白为什么。我在这里错了吗?

javascript vuejs2 vue-component arrow-functions
1个回答
0
投票

[我确定这是某物的重复,但是arrow函数使用了词法范围的this,因此this并不意味着您认为它在arrow函数内部的含义。

© www.soinside.com 2019 - 2024. All rights reserved.