javascript - How to simplify the code when importing multiple modules in js?
習慣沉默
習慣沉默 2017-06-12 09:22:00
0
5
892


Similar to this introduction of multiple modules, how to simplify it into one sentence, such as
import {A,B,C,D} from {'a.js' ,'b.js'....}

習慣沉默
習慣沉默

reply all(5)
学霸

Created index.js under ../img/new

import img1 from './banner.png'
...

module.exports = {
    img1,
    ...
}

You can quote it like this

import { img1, img2 ... } from '../img/new';
扔个三星炸死你

Never used this method before.

学习ing

If all the files on your right are js, it’s easy to solve, just write them all in one file improt {a, b, c} from xx.js, but the picture is...

迷茫

Take your file A that introduces multiple modules, package it separately into a module B, and then import and use module B.

学习ing

If you are using webpack you can write like this

const context = require.context('../img/new/', true, /\.(html)$/);
context.keys().forEach((filename) => {
    console.log(filename, context(filename));
});
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template