i'm quite new with vue.js i have several function that intended to compile them into one js file. like this:
example.js:
function containObject(obj, list) {
for (let i = 0; i < list.length; i += 1) {
if (list[i] === obj) {
return true;
}
}
return false;
} export default containObject;
function pad(n, width, z) {
let x = '';
let p = '';
x = z || '0';
p = n.toString();
return p.length >= width ? p : new Array(width - p.length + 1).join(x) + p;
} export default pad;
and import them in vue file like this:
example.vue:
import { containObject, pad } from './example';
but there was return error where cannot have two export default in one js file. how can icompile them into one file so that it can be used globally and no need to create the same function every file?
default
keyword. Just doexport function ...
, that's it. Then your import code would work – Eric Guan