After testing Vuex(3.0.1) in a Nativescript-vue (2.0) app I noticed that when using ModalView
s or ListView
s,
$store
is not available in the list items components or modal component. For now, use a StackLayout
for lists and I pass the $store
as a prop to the ModalView
:
<!-- Instead of a ListView -->
<StackLayout class="list-group">
<MyComponent v-for="item in items" :item="item" :key="item.id" class="list-group-item"/>
</StackLayout>
In MyComponent
, the method to open the modal is like:
import ItemForm from '../forms/ItemForm'
export default {
name: 'MyComponent',
props: {
item: { required: true, type: Object },
},
methods: {
openForm () {
const props = {item: this.item, store: this.$store} // props for ItemForm
this.$showModal(ItemForm, { props }) // Show ItemForm as a ModalView
},
},
}