Home

Issue: 129

nuxtServerInit and async data

[issue link]

I’m trying to load the data from an api with axios through a store action, but the SSR don’t wait the action finish.

There is any away to do it?

nuxtServerInit({ dispatch }) {
    return dispatch('core/load');
}

//core actions
import { list as categoryList } from '../../services/category';

export default {
  load({ commit }) {
    return categoryList().then(categories => {
      commit('setCategories', categories);
    });
  }
};

//category action
import apiHttp from './api';

export function list() {
  return apiHttp.get('/categories').then(response => response.data);
}

//api
import * as axios from 'axios';
import { API_URL } from '../config';

export default axios.create({
  baseURL: API_URL //http://localhost:3000/
});

Thanks!

This question is available on Nuxt.js community (#c106)