猿问

Vue 2.0如何仅使用Runtime-only Build构建项目?

计划用Vue 2.0弄一个个人博客以增加校招面试的谈资。参照各种Vue 1.0的博文大致建好项目之后,Vue报错如下:

[Vue warn]: Failed to mount component: template or render function not defined. (found in root instance)

百度Google啃文档一大轮得知2.0后npm导入的vue不含模板编译器,不少人的解决方案都是令vue指向vue/dist/vue.js,但是文档曰single-file component已经预编译好,并不需要模板编译器。但是页面的入口并不是single-file component,那么要怎么做才能把入口做成不需要模板编译器的样子呢?看Vue.js官方的例子vue-hackernews-2.0使用服务端渲染做的,那如果不用呢?

目前页面入口如下:

<!DOCTYPE html><html lang="en-US"><head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
  <title>Frontier of Marco's Self Struggling</title></head><body>
  <div id="container">
    <app></app>
  </div>
  <script src="dist/vendor.js"></script>
  <script src="dist/bundle.js"></script></body></html>
import Vue from 'vue'import App from './components/App.vue'var vm = new Vue({  el: '#container',  components: {    app: App
  }
})

PS. 前端小白一只,不怎么会表达自己的意思,请诸位大神多多担待


慕的地10843
浏览 495回答 1
1回答

神不在的星期二

你的App是什么?难道不是整个应用的基础结构么,为什么会写在components里,应该写在render function里面。var&nbsp;vm&nbsp;=&nbsp;new&nbsp;Vue({&nbsp;&nbsp;&nbsp;&nbsp;el:&nbsp;'#container',&nbsp;&nbsp;&nbsp;&nbsp;render:&nbsp;h&nbsp;=>&nbsp;h(App) })
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答