nuxtServerInit not being invoked

abh153k
13
abh153k
commented a year ago

Hi,
Here's my store/test.js:

export const state = () => ({
     latestCommitHash : '', 
     latestCommitDate: ''
 });

 export const mutations = { 
     setHash: (state,data) => {
         state.latestCommitHash = data[0];
         state.latestCommitDate = data[1];
     }   
 }

 export const actions = { 
     async nuxtServerInit ({commit}) {
         let commitData = await axios.get('/api/latestcommit');
         commit('setHash', JSON.parse(commitData.data));
     }   
 }

For reasons beyond me, I can't seem to make it work. nuxtServerInit is never being called. I tried giving a non-existent URL to axios.get but got no error (i.e. it is not being called.) However, if I put some random values in state function, I can access them in my templates. Am I missing something?

0
abh153k
13
abh153k
commented a year ago

I found the problem. For anyone else facing the same issue, nuxtServerInit works only on Classic mode. i.e. it works only in store/index.js. It's mentioned in the documentation. I missed that part.

0
Informations
Question โ€ข Resolved
#c8222 - Created a year ago