Level 2
Anyone? I spent few hours googling and trying to make it work with no success. Or am I posted to the wrong category?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi guys,
Can't figure out how to make computed property work with Vuex. Nova.liveStore.state gets updated after mutation, but cumputed (edit: lol) doesn't and returns initial empty object.
Can someone help with this, please?
// tool.js
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
Nova.booting((Vue, router) => {
router.addRoutes([
{
name: 'my-tool',
path: '/my-tool',
component: require('./components/Tool'),
},
])
Nova.liveStore = new Vuex.Store({
state: {
items:{},
},
actions: {
GET_ITEMS(context}) {
Nova.request().get('/api/items').then(response => {
context.commit('SET_ITEMS', response.data)
});
},
},
mutations: {
SET_ITEMS(state, items){
Nova.liveStore._vm.$set(state, 'items', [...items])
}
},
});
});
// Tool.vue
<template>
<div>
<div v-if="items">
<select>
<option value="null" disabled>Choose...</option>
<option v-for="item in items" :value="item.id">{{ item.title }}</option>
</select>
</div>
</div>
</template>
<script>
export default {
computed: {
items(){
return Nova.liveStore.state.items;
}
},
created() {
Nova.liveStore.dispatch('GET_ITEMS')
},
}
</script>
Please or to participate in this conversation.