vue 提示模板错误,求指导

vue 运行脚手架报错
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.
一直找不到哪里bug了 求大神求有可能哪里出错了

import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './router'
import './utils/rem'
import store from './store/'
import { routerMode } from './config/env'
import FastClick from 'fastclick'

if ('addEventListener' in document) {
  document.addEventListener('DOMContentLoaded', function () {
    FastClick.attach(document.body)
  }, false)
}
Vue.use(VueRouter)
const router = new VueRouter({
  routes,
  mode: routerMode,
  strict: process.env.NODE_ENV !== 'production',
  scrollBehavior (to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      if (from.meta.keepAlive) {
        from.meta.savedPosition = document.body.scrollTop
      }
      return {x: 0, y: to.meta.savedPosition || 0}
    }
  }
})

new Vue({
  router,
  store
}).$mount('#app')
阅读 24.8k
3 个回答
  • 根目录创建一个vue.config.js文件夹,加上如下代码即可。vue cli 3.10.0
module.exports = {
  runtimeCompiler: true
}

vue默认配置的是runtime版本。

clipboard.png

图片来自不同构建版本的解释说明

webpack.config.js 添加如下配置

resolve: {
    alias: {
        vue: 'vue/dist/vue.js',
    }
}

或者

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

或者

提取vue在html文件中直接引用(这种方法不推荐)

<script src="https://unpkg.com/vue"></script>

webpack.config.js 添加如下配置:

externals: {
  vue: 'Vue'
}
resolve: {
    alias: {
        vue: 'vue/dist/vue.js',
    }
}
推荐问题
logo
Microsoft
子站问答
访问
宣传栏