根据 Vue 文档:
处理模板与其他技术略有不同,因为大多数 webpack 模板加载器(例如 pug-loader)返回模板函数而不是已编译的 HTML 字符串。我们可以安装原始的 pug 来代替使用 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",
- "pug": "^2.0.3"
pug-loader
: https://github.com/pugjs/pug-loader - Brian Lee