我第一次尝试电子技术,我被它震撼了。然而,当我试图使用电子伪造的单文件vue.js组件时,我遇到了困难。我的问题如下:
我使用vue.js模板创建了一个项目并运行它。工作和看起来都很棒。我有一个包含索引文件的单个文件页面,如下所示:
<div id="test"></div>
</body>
<script>
import Vue from 'vue';
import Test from './test';
const app = new Vue(Test).$mount('#test');
app.text = "Electron Forge with Vue.js!";
</script>到现在为止还好。它导入Test,这是一个单独的文件组件并呈现它。
现在,我希望在这个主组件中嵌套其他单文件组件。例如,我希望在名为test.vue的应用程序文件中包含以下内容
<template>
<h2>Hello from {{text}}</h2>
</template>
<script>
import About from './About.vue'
export default {
components: {
appAbout: About,
},
data () {
return {
text: 'Electron'
}
}
}
</script>再说一次,到目前为止一切顺利。我可以没有错误地运行应用程序,因此组件正在被导入。
我的问题来了:如果我现在尝试使用<appAbout></appAbout>呈现组件,就像我以前在使用vue.js的web应用程序中所做的那样,我会得到以下错误。

它基本上是说我没有在我的组件中使用一个根元素,这真的很奇怪,因为我的组件看起来像这样:
<template lang="html">
<div>Hello from component</div>
</template>
<script>
export default {
}
</script>
<style lang="css">
</style>我被卡住了。有人能帮帮忙吗?
发布于 2018-04-29 23:32:41
因此,我尝试了一些不同的方法,但都没有成功,比如使用或甚至作为组件名称。
我还尝试了以下两种启动vue的方法:
使用电子伪造const app = new Vue(App).$mount('#app')的方法
我学习new Vue({el: '#app', render: h => h(App)})的方式
似乎什么都不起作用。
发布于 2018-04-30 02:48:11
按如下方式定义组件:
export default {
components: {
'app-about': About
}
}然后在模板中使用它,如下所示(使用kebab-case):
<app-about></app-about>关于编译模板错误,您需要将test.vue中的所有内容都包装在根元素中:
<template>
<div>
<h2>Hello from {{text}}</h2>
<app-about></app-about>
</div>
</template>https://stackoverflow.com/questions/50083970
复制相似问题