有以下几种导入的方式:
import {xx} from 'xx';import * as xx from 'xx';import xx from 'xx';var xx = require('xx');
import {xx} from ‘xx’;
与其对应的导出是:
// 导出的3种方式export const name = 'jack'const age = 18export { age }const first = 'jim'export { first as firstName }// 导入import { name as fullName, age, firstName } from 'xx';
import * as xx from ‘xx’;
// 导出export const name = 'jack'const age = 18export { age }const first = 'jim'export { first as firstName }// 导入import * as user from 'xx';// 使用console.log(user.age) // 18
import xx from ‘xx’
// 导出export default function() {console.log('haha')}// 导入import Fn from 'xx';Fn() // 'haha'
require(‘xx’)
// 导出module.export = {age: 18}module.export.name = 'jim'// 导入const user = require('xx')user.age // 18user.name // jim
