import xxx from和import {xxx} from的區別

  1. import xxx from

vue

import FunName from '../xxx'

js

export defualt function FunName() {
  return fetch({
    url: '/article/list',
    method: 'get'
  });
}
  1. import {xxx} from

vue

import {xxx} from '../xxx'

js

export function FunName() {
  return fetch({
    url: '/article/list',
    method: 'get'
  });
}

ES中的模塊導出導入
export 和 export default兩個導出,下面我們講講它們的區別:

  1. export與export default均可用於導出常量、函數、文件、模塊等;
  2. 在一個文件或模塊中,export、import可以有多個,export default僅有一個;
  3. 通過export方式導出,在導入時要加{ },export default則不需要;
  4. export能直接導出變量表達式,export default不行。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章