【Vue・axios】thenに引数に設定した関数が、アロー演算子を使った関数と基本の関数でthisの中身が違う
thenに引数に設定した関数が、アロー演算子を使った関数と基本の関数でthisの中身が違う。とりあえず、サンプルコード。
サンプルコード
・1つ目 methods: { deleteSample(id) { axios.delete(URL, {data: {id: id}}) .then(() => { console.log(this) }) } } ・2つ目 methods: { deleteSample(id) { axios.delete(URL, {data: {id: id}}) .then(function() { console.log(this) }) } } })
console.logの出力内容
・1つ目 VueComponent {_uid: 7, _isVue: true, $options: {…}, _renderProxy: Proxy, _self: VueComponent, …} ・2つ目 undefined
出力内容の違いについて、何故そうなるのか分からない。とりあえず、アロー演算子の仕様について確認しようと思う。