vuex-pathify: Having problems with sync() and object syntax
Hi,
I cannot make sync work with a nested object.
In my store, inside order.js I have:
import { make } from "vuex-pathify";
const state = {
order: {},
};
const mutations = make.mutations(state);
const defaultActions = make.actions(state);
const actions = {
...defaultActions,
setOrderItemQuantity: async (foo, payload) => {
//todo
console.log(foo);
console.log(payload);
},
};
const getters = make.getters(state);
export default {
state,
mutations,
actions,
getters,
};
inside the index.js
import Vue from "vue";
import Vuex from "vuex";
import order from "./Modules/order";
import pathify from "@/plugins/pathify";
import * as restActions from "./Modules/restActions";
const store = {
state: {},
mutations: {},
actions: { ...restActions },
modules: {
order: {
namespaced: true,
modules: {
order,
},
},
},
};
Vue.use(Vuex);
export default new Vuex.Store({
plugins: [pathify.plugin],
...store,
});
The order object loaded inside the state (via a rest action) is like this:
order = {
uuid: 1,
id: 1,
warranty: true,
orderItems: [
{
id: 1,
title: 'myTitle',
quantity: 10,
totalPrice: 100,
unitPrice: 10,
},
{
// other orderItem
},
{
// another one
}
]
};
Then in my component I’m trying to set a computed property for the v-model as seen in the doc\examples:
[...]
export default {
[...]
data() {
return {
index: 0 //this will be dynamic
};
},
computed: {
quantitySelected: sync("order/order@orderItems[:index].quantity|setOrderItemQuantity")
}
}
But that is not working.
What I’ve discovered so far:
quantitySelected: get("order/order@orderItems[0].quantitydoes work (I can print 10)quantitySelected: get("order/order@orderItems[:index].quantity|setOrderItemQuantity")does not work
Any idea what I’m doing wrong? Thank you
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 1
- Comments: 15 (6 by maintainers)
You said this is not working:
do this instead:
Hey, sorry for the long wait! I’ve had quite a busy couple of weeks myself.
I’ll look into this tomorrow