0๐
So looking at that code, it looks like you are trying to directly modify the store. You should change the state of the store via mutations. In an ideal setup, your component would have a method that would dispatch an action in the store. This asynchronous action would call the endpoint and then commit with a mutation.
state: {
pictures: []
},
mutations: {
addPicture(state, newPicture) {
state.pictures.push(newPicture)
}
}
Consult mutations and actions in the documentation here.
- [Vuejs]-Not able to use laravel-echo in vue cli project
- [Vuejs]-How to setFocus on Next button press event in Ionic-vue app?
0๐
Note that store.state.pictures
is an array of objects.
If you want to render all images, you can use v-for
. It will iterate over the array.
<template>
<div>
<img v-for="pic in storeState.pictures" :key="pic.id" :src="pic.url">
</div>
</template>
OR
If you want to display just information (id, urls),
<template>
<div>
<ul>
<li v-for="pic in storeState.pictures" :key="pic.id" > ID: {{pic.id}} | URL: {{pic.url}} </li>
</ul>
</div>
</template>
I assumed that storeState
is a computed property which is mapped to the your store.state
Thanks!
- [Vuejs]-Vues js pass object on redirect
- [Vuejs]-How to keep vuepress source files in custom directory?
0๐
My mistake, I had to change this.addPicture()
for store.addPicture()
:
axios.post(`http://127.0.0.1:8000/api/${this.endpoint}/`, fd, axiosConfig)
.then(res => {
let newPictureUrl = res.data.picture_1
let newPictureId = res.data.id
let addPicDic = {"url": newPictureUrl, "id": newPictureId}
store.addPicture(addPicDic) })
- [Vuejs]-Vue โ detect component inside slot
- [Vuejs]-Vue โ Accessing the Vue instance beforeEnter to access function
Source:stackexchange.com