I am trying to import a single function to my Vue component. I've created a separated js file for my function:
randomId.js:
exports.randomId = () => //My function ...
In my Vue component, I've imported the Random js:
let randomId = require('../functions/randomId');
randomId();
but Webpack throws an error of "randomId is not a function". I tried to import the file using import syntax, but the error remains.
import randomId from '../functions/randomId';
Should I use some other methods for importing single functions? I'm relatively new to Webpack and JS6.
You can pass strings, arrays, numbers, and objects as props. But can you pass a function as a prop? While you can pass a function as a prop, this is almost always a bad idea. Instead, there is probably a feature of Vue that is designed exactly to solve your problem.
STEP 01: First, Import the Child Component into the Parent Component inside script tag but above export default function declaration. STEP 02: Then, Register the Child Component inside the Parent Component by adding it to components object. STEP 03: Finally, Use the Child Component in the Parent Component Template.
You need to import the vue-multiselect in your main. js file to have access to the component. You also need to install it in your node_modules directory by running npm install vue-multiselect --save first.
Change your function module to properly use ES6 export:
export function randomId() { /*My function ...*/ }
And then use ES6 named import:
import { randomId } from '../functions/randomId';
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