Nuxt.js: Prefetch plugin data

Created on 18 Dec 2016  路  5Comments  路  Source: nuxt/nuxt.js

I created my custom translation plugin in which I extend Vue.

// Trans class here...

const translations = {}; // Need to fetch this json obj from server here

Vue.prototype._ = (key, params = {}) => {
  return trans.get(key, params);
};

How can I prefetch it so Vue can use it?
Thanks!

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

Most helpful comment

The middleware feature is out with the 0.9.8 release.

See the example with i18n.
Demo: http://i18n.nuxtjs.org/

All 5 comments

Hi @vadimsg

What you can do is:

const translations = require('./path-to-default-lang.json');

This way, Webpack will put your translation object directly in your bundle.js and the translations variable will be filled and ready to use with Vue.

Otherwise, the middleware option that will come in an upcoming release will let you fill the translations object from the server-side (but also from the client-side if the user change the langage).

In my situation I need to fetch it from api.

Thanks, waiting for the release!

The middleware feature is out with the 0.9.8 release.

See the example with i18n.
Demo: http://i18n.nuxtjs.org/

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

uptownhr picture uptownhr  路  3Comments

shyamchandranmec picture shyamchandranmec  路  3Comments

bimohxh picture bimohxh  路  3Comments

mikekidder picture mikekidder  路  3Comments

mattdharmon picture mattdharmon  路  3Comments