计划用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使用服务端渲染做的,那如果不用呢?
目前页面入口如下:
Frontier of Marco's Self Struggling
import Vue from 'vue'
import App from './components/App.vue'
var vm = new Vue({
el: '#container',
components: {
app: App
}
})
PS. 前端小白一只,不怎么会表达自己的意思,请诸位大神多多担待
用 vue-cli 建个简单工程先学着。
runtime 打包的是 /node_modules/vue/dist/vue.common.js
standalone 打包的是 /node_modules/vue/dist/vue.js
runtime 和 standalone 这两种方式对普通用户使用起来没区别,多数人都是在*.vue里写<template>...</template>,所以用runtime就够了。
你的App是什么?难道不是整个应用的基础结构么,为什么会写在components里,应该写在render function里面。
var vm = new Vue({ el: '#container', render: h => h(App) })