【发布时间】:2019-09-16 22:18:59
【问题描述】:
我是使用 Vue.js 的新手,我正在尝试学习如何使用 vue-star-rating 在我的 Laravel 应用程序中实现食谱评级系统。我想学习的第一件事是如何构建组件,然后将它们包含在我的刀片视图中。我已经在这里遇到了麻烦。 尝试包含开箱即用的 Laravel 附带的 ExampleComponent.vue,但我不明白如何将它包含在我的刀片文件中。 我的刀片文件的顶部看起来像这样
刀片视图
<div class="col-sm-6">
<div class="container recipeDesc">
<h2 class="text-center name">{{$recipe->title}}</h2>
<div class="stars">
<i class="fas fa-star"></i>
<i class="fas fa-star"></i>
<i class="fas fa-star"></i>
<i class="fas fa-star"></i>
<i class="fas fa-star"></i>
</div>
<div id="app">
<example-component></example-component>
</div>
默认 JS 文件
/**
* First we will load all of this project's JavaScript dependencies which
* includes Vue and other libraries. It is a great starting point when
* building robust, powerful web applications using Vue and Laravel.
*/
require('./bootstrap');
window.Vue = require('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('example-component', require('./components/ExampleComponent.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 app = new Vue({
el: '#app',
components: {
'example-component': require('./components/ExampleComponent.vue'),
}
});
如何在这个 div 中包含 ExampleComponent.vue?即使阅读 Vue.js 文档,也很难理解这一点。 谢谢!
【问题讨论】:
标签: javascript laravel vue.js