javascript - Laravel + Vuex: Object/argument destructuring not working -
i'm building vue application using vuex, , can't following code work (edited brevity, inspired this blog post).
// file: views/board.vue export default { methods: { updateprop (prop, value) { console.log(prop, value) // outputs prop , value this.$store.commit('board/updateprop', { [prop]: value }) } }, // ... } and in (named) vuex module:
// file: vuex/modules/board.js export default { mutations: { updateprop (state, { prop, value }) { console.log(prop, value) // outputs 'undefined undefined' } }, // ... } because import { } 'somewhere' works fine, i'm inclined believe object destructuring works. i'm baffeled why code doesn't.
i've created .babelrc file following, , installed respective plugins , presets, no avail.
{ "plugins": [ "transform-es2015-destructuring", "transform-object-rest-spread" ], "presets": [ ["es2015", { "modules": false }] ] } help appreciated.
this not answer, difficult fit comment. i'm not sure why both prop , value undefined, isn't how destructuring works (it not unpack key , value of object). current setup work if calling object has prop key , value key:
this.$store.commit('board/updateprop', { prop, value })
Comments
Post a Comment