|
export default new Vuex.Store({
state: {
items: [
{ Name: 'Andrew Fuller', Designation: 'Team Lead', Country: 'England' },
{ Name: 'Anne Dodsworth', Designation: 'Developer', Country: 'USA' },
{ Name: 'Janet Leverling', Designation: 'HR', Country: 'USA' },
{ Name: 'Laura Callahan', Designation: 'Product Manager', Country: 'USA' },
{ Name: 'Margaret Peacock', Designation: 'Developer', Country: 'USA' },
{ Name: 'Michael Suyama', Designation: 'Team Lead', Country: 'USA' },
{ Name: 'Nancy Davolio', Designation: 'Product Manager', Country: 'USA' },
{ Name: 'Robert King', Designation: 'Developer ', Country: 'England' },
{ Name: 'Steven Buchanan', Designation: 'CEO', Country: 'England' }
]
},
mutations: {
MUTATE_ITEMS: (state, items) => {
state.items = items;
}
},
actions: {
loadItems: (context, items) => {
context.commit("MUTATE_ITEMS", items);
}
},
getters: {
items(state) {
return state.items;
}
}
}); |
|
<template>
<h1>
<ejs-dropdownlist :dataSource='items' :fields='fields' ref="ddlInstance"></ejs-dropdownlist>
</h1>
</template>
<script>
import Vue from "vue";
import { mapGetters } from "vuex";
import { DropDownListPlugin } from "@syncfusion/ej2-vue-dropdowns";
Vue.use(DropDownListPlugin);
export default {
name: "ItemList",
data: function () {
return {
fields: { value: 'Designation' ,text: 'Name' }
}
},
beforeMount: function(e) {
this.items= this.$store.state.items;
},
computed: {
...mapGetters(["items"]),
items: {
set:function(){
return this.$store.state.items;
},
get:function(){
return this.$store.state.items;
}
}
}
};
</script> |
|
mutations: {
MUTATE_ITEMS: (state, items) => {
state.items = items;
},
ADD_ITEM: (state, item) => {
state.items.push(item)
state.items=[...state.items];
}
}, |