vueとvuexのES 6 Shorthand method names
1285 ワード
最近vueとvuexで開発されています.はい.vue単一ファイルのライフサイクルとvuexのactions定義には、pagという2つのコードがあります.vue
action.js中
抽出が
だから私はこれが何なのか悩んでいます.
ES 6にはcomputed propertyという概念があるという印象でMDNを調べてみました.最後に調べたのは計算属性ではなくshorthand methods namesです
計算プロパティは次のとおりです.
export default {
//...
created(){
this.$store.dispatch('getUsersSize')
}
//...
}
action.js中
const actions = {
getAllUsers({commit},url){
dataapi.getData(url,(users)=>{
commit(types.RECEIVE_USERS,{users})
})
}
}
抽出が
{created(){}}
と{getAllUsers({commit},url){}}
である通常の場合、関数をオブジェクトの属性値に付与し、方法と略称すると、{created:function(){}}
および{getAllUsers:function({commit},url){}}
と書くべきである.だから私はこれが何なのか悩んでいます.
ES 6にはcomputed propertyという概念があるという印象でMDNを調べてみました.最後に調べたのは計算属性ではなくshorthand methods namesです
// Shorthand method names (ES2015)
var o = {
property([parameters]) {}
};
計算プロパティは次のとおりです.
// Computed property names (ES2015)
var prop = 'foo';
var o = {
[prop]: 'hey',
['b' + 'ar']: 'there'
};
{created(){}}
と{created:function(){}}
をよく比較します.だからこのES 6 Shorthand method names文法糖は実は、':function'、コロンと'function'を省略しています.このスガルは甘くはないが、どうやら砂糖で、砂糖が多くなって自分の書いたバグが他の人には読めなくなった.人々はよく分からないものに対して、666(逃げる)と言います.