Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import and use luxon in a vuejs project?

I'm facing this error when I try to use luxon in my vuejs2 project.

Uncaught TypeError: Cannot read property 'local' of undefined

I installed the lib using npm, and imported in my component :

import DateTime from 'luxon'
const exmpl = DateTime.local()

Can you guys show me what I did wrong or even propose an other librairie for time manipulation that can work easily with vuejs.

like image 784
Imad BELHAUSS Avatar asked Dec 19 '25 06:12

Imad BELHAUSS


1 Answers

Importing

I'd like to make an explanation with general ES6 syntax.

Let’s import those amazing helpful helper functions:

import { sayName, sayAnimal } from './Helpers';
import whatsYourFlava from './Helpers';
sayName('Sam');
//Hello Sam
sayAnimal('Giraffe');
//What animal? Giraffe
whatsYourFlava('grapes');
//I'm liking grapes

When importing named exports, you’ll have to wrap them in curly braces. If you’re importing multiple exports from the same module, you can concatenate them, comma based, and use them in the same wrapping curly braces. This looks a lot like destructuring in ES6, but actually doesn’t have anything to do with it.

When you import, and omit the curly braces, it will look for the default export in the module you’re importing from. Because it knows it has to look for the default export, you can use any random name for your import. This will work too:

import bruhGetMoney from './Helpers';
bruhGetMoney('money');
//I'm liking money

I hope this would be a clearer thing for you. Thanks.

like image 126
egor518 Avatar answered Dec 20 '25 19:12

egor518



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!