我开始在Laravel项目中使用vue js。我安装了所有软件包,但是我的问题是当我尝试在另一个组件中调用一个组件并运行以下命令时:
npm run dev
我从webpack中出错。
我的代码:
父组件 TabelReception.vue :
<template>
<stats-card></stats-card>
<table class="table">
<tbody>
</tbody>
</table>
</template>
<script>
import StatsCard from './StatsCard'
Vue.component('StatsCard', StatsCard)
export default {
components: {
'stats-card': StatsCard
}
}
</script>
即将推出的组件 StatsCard.vue :
<template>
<h2>
hi bro just a test
</h2>
</template>
<script>
export default {
}
</script>
app.js :
import Vue from 'vue'
/**
* The following block of code may be used to automatically register your
* Vue components. It will recursively scan this directory for the Vue
* components and automatically register them with their "basename".
*
* Eg. ./components/ExampleComponent.vue -> <example-component></example-component>
*/
// const files = require.context('./', true, /\.vue$/i)
// files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default))
Vue.component('reception-table', require('./components/TableReception.vue').default);
Vue.component('stats-card', require('./components/StatsCard.vue').default);
/**
* Next, we will create a fresh Vue application instance and attach it to
* the page. Then, you may begin adding components to this application
* or customize the JavaScript scaffolding to fit your unique needs.
*/
const core = new Vue({
el: '#core'
});
请帮助。
答案 0 :(得分:0)
该组件在模板部分仅允许单个元素。如果需要使用多个,请用div
包裹起来,然后像
<template>
<div>
<stats-card></stats-card>
<table class="table">
<tbody>
</tbody>
</table>
</div>
</template>
您无需同时使用两种方法来注册组件
<script>
import StatsCard from './StatsCard'
export default {
components: {
StatsCard
}
}
</script>
答案 1 :(得分:0)
<template>
<div>
<stats-card>
</stats-card>
<table class="table">
<tbody>
</tbody>
</table>
</div>
</template>
<script>
import StatsCard from './statccard'
export default {
components: {
'stats-card': StatsCard
}
}
</script>
the template root on requires one ony one element but you have also iported the component wrongly