javascript - 当js里有多个export怎么引入?
伊谢尔伦
伊谢尔伦 2017-05-19 10:11:30
[JavaScript讨论组]
// mutation-types.js
export const SOME_MUTATION = 'SOME_MUTATION'
export const SOME_MUTATION_1 = 'SOME_MUTATION_1'

我要import引入mutation-types.js,怎么写比较好?

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

全部回复(7)
大家讲道理
import * as types from 'mutation-types.js'
// types.SOME_MUTATION types.SOME_MUTATION_1
習慣沉默
import * as TYPES from './mutation-types';

console.log(TYPES.SOME_MUTATION)
PHPz
如果你想全部导入:
import * as mutationTypes from './mutation-types';
如果你只是想导入 mutation-types里的几个可以:

import {SOME_MUTATION,SOME_MUTATION_1} from './mutation-types';
ringa_lee

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

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

export obj
ringa_lee

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

给我你的怀抱

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

漂亮男人
import * as types from './types';

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

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号