This repository has been archived on 2021-09-06. You can view files and clone it, but cannot push or open issues or pull requests.
2021-05-04 18:05:03 +02:00
|
|
|
import { createStore } from 'vuex';
|
|
|
|
|
|
|
|
const store = createStore({
|
|
|
|
state() {
|
|
|
|
return {
|
|
|
|
counter: 0
|
|
|
|
};
|
2021-05-04 21:49:40 +02:00
|
|
|
},
|
|
|
|
mutations: {
|
|
|
|
increment(state) {
|
|
|
|
state.counter = state.counter + 1;
|
2021-05-04 22:13:48 +02:00
|
|
|
},
|
|
|
|
increase(state, payload) {
|
|
|
|
state.counter = state.counter + payload.value;
|
2021-05-04 21:49:40 +02:00
|
|
|
}
|
2021-05-04 22:20:06 +02:00
|
|
|
},
|
|
|
|
getters: {
|
|
|
|
finalCounter(state) {
|
|
|
|
return state.counter * 3;
|
|
|
|
},
|
|
|
|
normalizedCounter(_, getters) {
|
|
|
|
const finalCounter = getters.finalCounter;
|
|
|
|
if (finalCounter < 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (finalCounter > 100) {
|
|
|
|
return 100;
|
|
|
|
}
|
|
|
|
return finalCounter;
|
|
|
|
}
|
2021-05-04 18:05:03 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default store;
|