Answer the question
In order to leave comments, you need to log in
Why doesn't reactivity (VUEX) work?
I'm trying to write a notification module for VUEjs using a repository.
notify.js
export default {
state: {
Notifyes: [
{title:'Default notify', desc:'some desc', type:'info', timeout:false}
]
},
getters: {
Notifyes(state) {
console.log('getter Notifyes');
return state.Notifyes;
}
},
mutations: {
addNotify(state, notify = {title:'Empty notify', desc:'', type:'error', timeout:false}) {
//types: danger warning success info primary secondary light
console.log('mutation addNotify');
state.Notifyes.push(notify);
}
},
actions: {
addNotify(ctx, notify) {
console.log('action addNotify ');
ctx.commit('addNotify', notify);
}
}
}
<template>
<div class="notifyes">
<notify v-for="(Notify, id) in Notifyes"
v-bind:key="id"
v-bind:title="Notify.title"
v-bind:desc="Notify.desc"
v-bind:type="Notify.type"
>
</notify>
</div>
</template>
<script>
import Notify from './components/Notify.vue'
import {mapGetters} from "vuex";
export default {
name: 'notifyes',
computed: {
...mapGetters(['Notifyes'])
},
mounted() {
console.log('mounted');
},
updated() {
console.log('updated');
},
components: {
Notify
}
}
</script>
getter Notifyes
mounted
action addNotify
mutation addNotify
action addNotify
mutation addNotify
action addNotify
mutation addNotify
action addNotify
mutation addNotify
action addNotify
mutation addNotify
updated
data: function() {
return {
Notifyes: this.$store.state.Notify.Notifyes
}
},
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question