あるvueのexampleに下記コードがありました。
vuejs
1created() { 2 this.selectedTeacher = this.$store.getters.teachers.find(i => `${i.id}` === this.$route.params.id) 3}
iを見たくて下記のように変更しました。
vuejs
1created() { 2 this.selectedTeacher = this.$store.getters.teachers.find( 3 function(i){ 4 console.log(i); 5 return i.id === this.$route.params.id 6 } 7 ) 8}
iは表示されたのですがreturn i.id === this.$route.params.idのところで下記エラーになりました。
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '$route')
なぜ普通のfunctionにすると未定義のプロパティ(google翻訳)になるのでしょうか?
また、このエラーを回避する方法はありますか?

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/07/15 03:06
2022/07/15 03:52
2022/07/15 04:07
2022/07/15 04:39
2022/07/15 04:42