亚洲中字慕日产2020,大陆极品少妇内射AAAAAA,无码av大香线蕉伊人久久,久久精品国产亚洲av麻豆网站

資訊專欄INFORMATION COLUMN

Vuejs 的 dist 文件使用指南

gghyoo / 2206人閱讀

摘要:平時(shí)的即后綴文件不需要版本,直接即可。解決方案這里使用配置的為例,整理為個(gè)版本的配置。使用時(shí)加載版本。比如的介紹還有前所未有的塊新語法,讓支持覆蓋子組件樣式問題最近的表示可以用代替用這么潮的框架,就是累人啊啊啊啊。

問題

項(xiàng)目里幾個(gè) Vuejs 版本都遇到過 vue.runtime.common.js 的報(bào)錯(cuò)提示:

vue 2.0.7

vue.runtime.common.js:519 [Vue warn]: Failed to mount component: template or render function not defined.

vue 2.1.0

vue.runtime.common.js:511 [Vue warn]: Failed to mount component: template or render function not defined.

vue 2.2.6

vue.runtime.common.js:556 [Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build.

原因

查了 Vuejs 的 Release log 和 Readme 等,找出原因是 Vuejs 區(qū)分 Full 與 Runtime-only 版本。平時(shí)的 Vue Single File Component (即 .vue 后綴文件)不需要 Full 版本,直接 import Vue from "vue" 即可。

而如果用到 Vue.extend({}) 手動(dòng)構(gòu)造 Vue 組件的, import Vue from "vue" 會(huì)報(bào)上面的錯(cuò)誤。要換成 vue/dist/vue.js 或 vue/dist.common.js 或 vue/dist/vue.esm.js (更多可看 : Vue Github/Explanation of Build Files )。

我的各項(xiàng)目的 Vue 版本因?yàn)槟承┰驎簳r(shí)沒對(duì)齊,所以要把各版本的整理下。

解決方案

這里使用 Webpack 配置 Vuejs 的 alias 為例,整理為 3 個(gè)版本的配置。使用時(shí) import vue from "fullVue" 加載 Full 版本。

module.exports = {
  // ...
  resolve: {
    alias: {
      "fullVue": "vue/dist/vue.esm.js" // vue 2.2.0 及以后并使用 webpack 2.0
    }
  }
}
module.exports = {
  // ...
  resolve: {
    alias: {
      "fullVue": "vue/dist/vue.common.js" // vue 2.1.0 及以后,vue 2.2.0 以前, 或者 vue 2.2.0 以后但使用 webpack 1.0
    }
  }
}
module.exports = {
  // ...
  resolve: {
    alias: {
      "fullVue": "vue/dist/vue.js" // vue 2.1.0 以前
    }
  }
}
后記

Vuejs 是個(gè)很潮的框架,各種新東西都被作者引入進(jìn)來。比如 2.2.0 的 Release log 介紹:

The default export used by Webpack 2 will now point to an ES module build (dist/vue.runtime.esm.js). This means without any alias configuration, require("vue") in webpack 2 will give you an object ({ __esModule: true, default: Vue }) instead. You should only use import Vue from "vue" with webpack 2.

還有 vue-loader 前所未有的 style 塊新語法,讓 Vue Single File Component 支持覆蓋子組件樣式問題:

.foo >>> .bar { color: red; }

vue-loader 最近的 release 表示可以用 /deep/ 代替 >>>

    <