【发布时间】:2018-12-06 23:51:28
【问题描述】:
来自 Vue documentation:
处理模板有点不同,因为大多数 webpack 模板加载器(例如 pug-loader)返回模板函数 一个已编译的 HTML 字符串。而不是使用 pug-loader,我们可以 安装原版哈巴狗。
TestComponent.vue:
<template lang="pug">
div
h2 {{ message }}
</template>
<script>
export default {
data () {
return {
message: 'Done!!! Done...'
}
}
}
</script>
main.js:
import Vue from 'vue'
import TestComponent from './../components/TestComponent/TestComponent.vue'
new Vue({
el: '#app',
render: h => h(TestComponent)
});
错误:
NonErrorEmittedError: (Emitted value instead of an instance of Error)
Error compiling template:
div
h2 {{ message }}
- Component template requires a root element, rather than just text.
使用的依赖版本:
- “webpack”:“^4.7.0”
- “vue”:“^2.5.16”
- “vue-loader”:“^15.2.4”,
- "vue-template-compiler": "^2.5.16",
- “哈巴狗”:“^2.0.3”
【问题讨论】:
-
安装
pug-loader:github.com/pugjs/pug-loader -
它在the documentation 中说你需要使用pug-plain-loader
-
注意:您提供的documentation link 用于 vue-loader v14,但您使用的是 v15。
标签: javascript webpack vue.js vuejs2