I have below files and could not find the reason for warning "Classic mode for store/ is deprecated and will be removed in Nuxt 3". Everything works fine just getting that annoying warning.
modules/data.js file in store of nuxt.js.
const state = () => ({
loadedPosts: []
});
const mutations = {
setPosts(state, posts){
state.loadedPosts = posts;
}
};
const actions = {
setPosts(vuexContext, posts){
vuexContext.commit('setPosts', posts);
}
};
const getters = {
loadedPosts(state){
return state.loadedPosts;
}
};
export default {
state,
actions,
getters,
mutations
};
index.js file in store of nuxt.js.
import Vuex from 'vuex';
import data from "~/store/modules/data";
const createStore = () => {
return new Vuex.Store({
modules: {
data: {
namespaced: true,
...data
}
}
});
};
export default createStore;
Using a store to manage the state is important for every big application. That's why Nuxt implements Vuex in its core.
Vue 3 and Vite SupportWith Nuxt 3 being written in Vue 3, you get access to features like the Composition API, better module imports, and overall improved app performance. Nuxt 3 also comes with Vite support, which is backwards compatible with Nuxt 2.
Nuxt. js is a framework for creating Vue. js applications. Its goal is to help Vue developers take advantage of top-notch technologies, fast, easy and in an organized way.
Finally, after reading a lot of answers and blogs I figured out the solution.
Important:- Forgot what you know about vuex module in vue.js app. Using Vuex in nuxt.js is a bit different.
Solution:- Nuxt.js lets you have a store directory with every file corresponding to a module. Just add necessary files in the store directly you don't need to create and add files to 'modules' directory in store. index.js file is a special file and this is where we would put the logic that is not related to a module.
store/data.js
export const state = () => ({
loadedPosts: []
});
export const mutations = {
setPosts(state, posts){
state.loadedPosts = posts;
}
};
export const actions = {
setPosts(vuexContext, posts){
vuexContext.commit('setPosts', posts);
}
};
export const getters = {
loadedPosts(state){
return state.loadedPosts;
}
};
Using state in project
this.$store.data.loadedPosts
Using mutations in project
this.$store.commit('data/setPosts', [{id: '1',...}, {id: '2',...}]);
Using actions in project
this.$store.dispatch('data/setPosts', [{id: '1',...}, {id: '2',...}]);
Using getters in project
this.$store.getters['data/loadedPosts'];
Important References:-
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With