search

Home  >  Q&A  >  body text

javascript - How to simplify the code when importing multiple modules in js?


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'....}

習慣沉默習慣沉默2763 days ago898

reply all(5)I'll reply

  • 欧阳克

    欧阳克2017-06-12 09:24:00

    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';

    reply
    0
  • 扔个三星炸死你

    扔个三星炸死你2017-06-12 09:24:00

    Never used this method before.

    reply
    0
  • 学习ing

    学习ing2017-06-12 09:24:00

    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...

    reply
    0
  • 迷茫

    迷茫2017-06-12 09:24:00

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

    reply
    0
  • 学习ing

    学习ing2017-06-12 09:24:00

    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));
    });

    reply
    0
  • Cancelreply