suchen

Heim  >  Fragen und Antworten  >  Hauptteil

javascript - Wie führe ich mehrere Exporte ein, wenn es in JS mehrere Exporte gibt?

// mutation-types.js
export const SOME_MUTATION = 'SOME_MUTATION'
export const SOME_MUTATION_1 = 'SOME_MUTATION_1'

Ich möchte mutation-types.js importieren. Wie kann ich es besser schreiben?

伊谢尔伦伊谢尔伦2832 Tage vor773

Antworte allen(7)Ich werde antworten

  • 大家讲道理

    大家讲道理2017-05-19 10:13:30

    import * as types from 'mutation-types.js'
    // types.SOME_MUTATION types.SOME_MUTATION_1

    Antwort
    0
  • 習慣沉默

    習慣沉默2017-05-19 10:13:30

    import * as TYPES from './mutation-types';
    
    console.log(TYPES.SOME_MUTATION)

    Antwort
    0
  • PHPz

    PHPz2017-05-19 10:13:30

    如果你想全部导入:
    import * as mutationTypes from './mutation-types';
    如果你只是想导入 mutation-types里的几个可以:
    
    import {SOME_MUTATION,SOME_MUTATION_1} from './mutation-types';

    Antwort
    0
  • ringa_lee

    ringa_lee2017-05-19 10:13:30

    你可以吧SOME_MUTATION和SOME_MUTATION_1放在一个export的对象里面呀:

    let obj = {
        SOME_MUTATION : 'SOME_MUTATION',
        SOME_MUTATION_1 : 'SOME_MUTATION_1'
    }
    
    export obj

    Antwort
    0
  • ringa_lee

    ringa_lee2017-05-19 10:13:30

    http://es6.ruanyifeng.com/#do...

    Antwort
    0
  • 给我你的怀抱

    给我你的怀抱2017-05-19 10:13:30

    引入
    import * as types from '../../mutation-types';
    使用
    types.SOME_MUTATION
    types.SOME_MUTATION_1

    Antwort
    0
  • 漂亮男人

    漂亮男人2017-05-19 10:13:30

    import * as types from './types';

    然后用 types[导出名] 可以使用

    Antwort
    0
  • StornierenAntwort