金狮镖局 Design By www.egabc.com
在使用vue导出时会有一个default关键字,下面举例说明下在导出时使用export和export default的对应的imort写法的区别
一、部分导出和部分导入
部分导出和部分导入的优势,当资源比较大时建使用部分导出,这样一来使用者可以使用部分导入来减少资源体积,比如element-ui官方的就推荐使用部分导入来减少项目体积,因为element-ui是一个十分庞大的框架,如果我们只用到其中的一部分组件, 那么只将用到的组件导入就可以了。
1.1部分导出的写法
export function helloWorld(){ conselo.log("Hello World"); } export function test(){ conselo.log("this's test function"); }
另一种写法,这种方法比较不推荐,因为看起来会比较乱。
var helloWorld=function(){ conselo.log("Hello World"); } var test=function(){ conselo.log("this's test function"); } export helloWorld export test
1.2部分导入
只导入需要的资源
import {helloWorld} from "./utils.js" //只导入utils.js中的helloWorld方法 helloWorld(); //执行utils.js中的helloWorld方法
1.3部分导出——全部导入
如果我们需要utils.js中的全部资源则可以全部导入
import * as utils from "./utils.js" //导入全部的资源,utils为别名,在调用时使用 utils.helloWorld(); //执行utils.js中的helloWorld方法 utils.test(); //执行utils.js中的test方法
二、全部导出和全部导入
如果使用全部导出,那么使用者在导入时则必须全部导入,推荐在写方法库时使用部分导出,从而将全部导入或者部分导入的权力留给使用者。
2.1全部导出
需要注意的是:一个js文件中可以有多个export,但只能有一个export default
var helloWorld=function(){ conselo.log("Hello World"); } var test=function(){ conselo.log("this's test function"); } export default{ helloWorld, test }
2.2全部导入
import utils from "./utils.js" utils.helloWorld(); utils.test();
总结
以上所述是小编给大家介绍的Vue export import 导入导出的多种方式与区别介绍,希望对大家有所帮助!
金狮镖局 Design By www.egabc.com
金狮镖局
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
金狮镖局 Design By www.egabc.com
暂无Vue export import 导入导出的多种方式与区别介绍的评论...
更新日志
2024年10月07日
2024年10月07日
- 群星《前途海量 电影原声专辑》[FLAC/分轨][227.78MB]
- 张信哲.1992-知道新曲与精丫巨石】【WAV+CUE】
- 王翠玲.1995-ANGEL【新艺宝】【WAV+CUE】
- 景冈山.1996-我的眼里只有你【大地唱片】【WAV+CUE】
- 群星《八戒 电影原声带》[320K/MP3][188.97MB]
- 群星《我的阿勒泰 影视原声带》[320K/MP3][139.47MB]
- 纪钧瀚《胎教古典音乐 钢琴与大提琴的沉浸时光》[320K/MP3][148.91MB]
- 刘雅丽.2001-丽花皇后·EMI精选王【EMI百代】【FLAC分轨】
- 齐秦.1994-黄金十年1981-1990CHINA.TOUR.LIVE精丫上华】【WAV+CUE】
- 群星.2008-本色·百代音乐人创作专辑【EMI百代】【WAV+CUE】
- 群星.2001-同步过冬AVCD【环球】【WAV+CUE】
- 群星.2020-同步过冬2020冀待晴空【环球】【WAV+CUE】
- 沈雁.1986-四季(2012梦田复刻版)【白云唱片】【WAV+CUE】
- 纪钧瀚《胎教古典音乐 钢琴与大提琴的沉浸时光》[FLAC/分轨][257.88MB]
- 《国语老歌 怀旧篇 3CD》[WAV/分轨][1.6GB]