export + export default +as

【export + export default +as】
export import

    • export
    • export + export default
        • export default
        • export + export default
      • export default 注意事项
      • as关键字

export
type.js export const a = 1 export const b = [1,2,3] export function c(){...} export const d = function (){...} 等价于 const a = 1 const b = [1,2,3] function c(){...} const d = function (){...} export {a,b,c,d} // 导出 import {a,b,a,d} from '@/utils/type'

export + export default export default
export default function (name) { console.log(name) } // 导出 import file from '@/utils/type' file(5)// 5

export + export default
// 导出 export const fileType = function (name) { console.log(name) } export default function (name) { console.log(name) } // 导入 import * as fileType from '@/utils/type' fileType.fileType ('aaa') // aaa fileType.default ('sss') // sss // 或者 import fileTypedefault,{ fileType } from '@/utils/type' fileType ('aaa') // aaa fileTypedefault ('sss') // sss

export default 注意事项
export default后面不可以用 var、let、const 可用 export default function(){} function add(){}
as关键字
export function sampleA (name) { console.log(name) } export function sampleB (name) { console.log(name) } export function sampleC (name) { console.log(name) } export default function (name) { console.log(name) } // 导出多个使用别名 import { sampleA as funE, sampleB as funF, sampleC } from '@/utils/type' // 或者 import sample, { sampleA as funE, sampleB as funF } from '@/utils/type'funE('333') // 333 funF('555') // 555 sampleC('666') // 666 sample('default') // default

    推荐阅读