how to use vuex in vue? #300
Answered
by
joelgenaro
albayanidev
asked this question in
Q&A
-
I have a vue project and how can I use vuex there? |
Beta Was this translation helpful? Give feedback.
Answered by
joelgenaro
Apr 8, 2024
Replies: 1 comment 1 reply
-
hi here is my solution: import { createStore } from 'vuex'; const store = createStore({ export default store; import { createApp } from 'vue'; const app = createApp(App); Count: {{ count }} Increment |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
albayanidev
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi here is my solution:
import { createStore } from 'vuex';
const store = createStore({
state() {
return {
count: 0,
};
},
mutations: {
increment(state) {
state.count++;
},
},
actions: {
increment(context) {
context.commit('increment');
},
},
});
export default store;
import { createApp } from 'vue';
import store from './store';
import App from './App.vue';
const app = createApp(App);
app.use(store);
app.mount('#app');
Count: {{ count }}
Increment