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
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.
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, };
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.
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
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