1. 程式人生 > >import * as xxx from 'xxx'和不帶*as(即import xxx from 'xxx')的區別

import * as xxx from 'xxx'和不帶*as(即import xxx from 'xxx')的區別

下圖中一個import有* as, 一個import後沒有 * as
圖一
他們的區別如下:
此為getters.js檔案內容
在這裡插入圖片描述
結論:

  • import * as xxx from ‘xxx’: (export const books =state => state.bookInfo
    export const buyBooks =state => state.added)會將 若干export匯出的內容組合成一個物件返回;
  • import xxx from ‘xxx’:(export default mutations)只會匯出這個預設的物件作為一個物件,