不去做怎么知道做不到,用心做好每一天做好每一件|

轻风细雨_林木木

园龄:6年3个月粉丝:4关注:1

vue 中 export 及 export default 的区别

参考:https://www.cnblogs.com/fangshidaima/p/7206137.html

 

vue 中 export、export default、import的具体区别

 

在ES6中,export与export default均可用于导出常量、函数、文件、模块等,你可以在其它文件或模块中通过 import(常量 | 函数 | 文件 | 模块)的方式,将其导入,以便能够对其进行使用,但在一个文件或模块中,export、import可以有多个export default仅有一个

 

export 使用:

1
2
3
4
5
6
//demo1.js
export const str = 'hello world'  // 常量
  
export function fun(a){  // 函数
    return a+1
}

 

导入:

1
2
//demo2.js
import { str , fun } from 'demo1' // 使用export的时候使用{}包起来

 

export default 使用

1
2
//demo3.js
export default const str = 'hello world'

 

导入:

1
2
//demo4.js
import str from 'demo3' //导入的时候没有花括号

  

 

 

本文作者:轻风细雨_林木木

本文链接:https://www.cnblogs.com/linzhifen5/p/11904028.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   轻风细雨_林木木  阅读(11283)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 尚好的青春 孙燕姿
  2. 2 孙燕姿
  3. 3 克卜勒 孙燕姿
- 孙燕姿
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.