I have googled this error however the answers I get, didn't help me. I am trying to make a like-dislike count with using Vuex. I am using jsonplaceholder for data. Here I take my data and setting a like attribute for all the objects.
actions: {
async fetchPhotos({commit}) {
const response = await axios.get('https://jsonplaceholder.typicode.com/photos');
commit('setPhotos', response.data.splice(0,100))
},
}
mutations: {
setPhotos: (state, photos) => {
(state.albumList = photos);
state.albumList.forEach(element => element.likes = 0)}
}
After in my dom I want to use one button for dislike and other for like. I want to display the like counter when I click the buttons.
<div v-for="photos in allPhotos" :key="photos.id">
<div class="card" @click="detail(photos)"><img :src="photos.thumbnailUrl" alt=""></div>
<div class="likes">
<div class="myButton" ><button class="red" @click="minus(photos.id)"><i class="fas fa-minus"></i></button></div>
<div>{{photos.likes}}</div>
<div class="myButton "><button class="green" @click="plus(photos.id)"><i class="fas fa-plus"></i></button></div>
</div>
</div>
So I added minus mutations in my store and in my script.
methods: {
...mapMutations(['minus']),
state: {
albumList : [],
},
mutations: {
minus: (state, id) => {
state.albumList[id-1].likes--
},
After all this, I am having an error:
[vuex] unknown mutation type: minus.
I can't see what I am doing wrong here.
PS:I also trimmed the code for it to be clearer.