安装与使用vue-cli 3.0以上版本

------------恢复内容开始------------

安装vue-cli 3.0以上版本

由于初学vue的原因,起初安装的vue-cli的版本停留在3.0以下,现对安装vue-cli 3.0以上版本重新做记录

安装

npm install @vue/cli -g

初始化项目

vue create {项目名}

其后按照提示向下即可

启动项目

npm run serve

兼容性

自vue-cli 2.x 升级至 vue-cli 3.0 以上版本后,会出现

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.

报错,这是由于vue-cli两代的默认运行模式不同的问题,需要将main.js中的初始化vue改成类似

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount("#app")

即可

当然,也可以在vue.config.js中加上

configureWebpack: {
    resolve: {
      alias: {
        'vue$': 'vue/dist/vue.esm.js' 
      }
    }

或在引用vue时改写成

import Vue from 'vue/dist/vue.esm.js'

------------恢复内容结束------------

posted @ 2020-12-23 00:16  springfield_psk  阅读(124)  评论(0编辑  收藏  举报