Gabotronix
5 months ago

About importing a javascript function from ther file

Posted 5 months ago by Gabotronix

Hi everybody, I have a javascript file where I have a function, my file dates.js looks like this.

export function parsedDate(usedDate){
    return Vue.moment(usedDate).format('D/M/YYYY -  HH:mm:ss');
};

Now in order to use this function I import it into my vue component like this:

import { parsedDate } from '../../../config/dates.js';

I thought this would be enough to use the function inside my component but in rder to not get "is not a function" error I have to add it into my component's data, like this:

data() {
    return {
        parsedDate: parsedDate,
    }
},

Can anyone explain why this happens, in my opinion having to add the function to my data section doesn't feel right, is there a reasn for this? a better way to import logic from other files into my component?

Please sign in or create an account to participate in this conversation.