Maison > Questions et réponses > le corps du texte
// mutation-types.js
export const SOME_MUTATION = 'SOME_MUTATION'
export const SOME_MUTATION_1 = 'SOME_MUTATION_1'
Je souhaite importer mutation-types.js, comment mieux l'écrire ?
大家讲道理2017-05-19 10:13:30
import * as types from 'mutation-types.js'
// types.SOME_MUTATION types.SOME_MUTATION_1
習慣沉默2017-05-19 10:13:30
import * as TYPES from './mutation-types';
console.log(TYPES.SOME_MUTATION)
PHPz2017-05-19 10:13:30
如果你想全部导入:
import * as mutationTypes from './mutation-types';
如果你只是想导入 mutation-types里的几个可以:
import {SOME_MUTATION,SOME_MUTATION_1} from './mutation-types';
ringa_lee2017-05-19 10:13:30
Vous pouvez mettre SOME_MUTATION et SOME_MUTATION_1 dans un objet d'export :
let obj = {
SOME_MUTATION : 'SOME_MUTATION',
SOME_MUTATION_1 : 'SOME_MUTATION_1'
}
export obj
给我你的怀抱2017-05-19 10:13:30
Introduire
importer * en tant que types à partir de '../../mutation-types' ;
Utiliser
types.SOME_MUTATION
types.SOME_MUTATION_1
漂亮男人2017-05-19 10:13:30
import * as types from './types';
Ensuite, utilisez les types[nom de l'export] à utiliser