Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to store constants in Nuxt?

I have a nuxt project (vuejs) and I'm wondering how to store constants in my project ? ( about 50 constants).

Thank you for your response. kaboume

like image 900
Ricou Avatar asked Feb 01 '19 10:02

Ricou


People also ask

Is Nuxt SEO friendly?

Nuxt, one of the most popular Vue frameworks for new web apps, can greatly improve your app performance and SEO. One of the most important Nuxt configurations is the mode, as it determines how your app is built, deployed, and served.

How do you define a constant in Vuejs?

To define common constants in Vue. js, we can create a module that export an object with the constant values. const DELIVERY = "Delivery"; const CARRIER = "Carrier"; const COLLATION = "Collation"; const CASH_AND_CARRY = "Cash and carry"; export default { DELIVERY, CARRIER, COLLATION, CASH_AND_CARRY, };

When should you use Nuxt js instead of Vue js?

You just create the directory and files, and Nuxt does all of the work. But the cons are that it is less controllable and manageable than a manually written one. With Vue. js you can easily add your own logic to the router, import services and have more control managing routes than with a manually generated router.


1 Answers

I you can create a constants.js file and

 // constants.js
 export const CONSTANT_1 = 'CONSTANT_1';
 export const CONSTANT_2 = 'CONSTANT_2';
 export const CONSTANT_3 = 'CONSTANT_3';

 // And call it like this
 import { CONSTANT_1 } from 'constants';

thanks

like image 159
Birante Avatar answered Oct 17 '22 04:10

Birante