[英]Registering a 2nd component? Vue.js Laravel6
I have created a fresh Laravel6 project to work out how to register components...我创建了一个新的 Laravel6 项目来研究如何注册组件......
I have cloned ExampleComponent.vue to ExampleComponent2.vue我已经克隆ExampleComponent.vue到ExampleComponent2.vue
// ExampleComponent2.vue // ExampleComponent2.vue
<template>
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">Example2 Component</div>
<div class="card-body">
I'm an example2 component.
</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
mounted() {
console.log('Component2 mounted.')
}
}
</script>
// app.js // app.js
Vue.component('example-component', require('./components/ExampleComponent.vue').default);
Vue.component('example-component2', require('./components/ExampleComponent2.vue').default);
// login.blade.php - I have placed this under the closing tag and @endsection to test on the login page... // login.blade.php - 我已经把它放在结束标签和@endsection 下以在登录页面上测试......
<example-component2></example-component2>
I have run "npm run watch" in command line and there are no error messages...我在命令行中运行了“npm run watch”并且没有错误消息......
When I load the login route, I open the console to see this error message?当我加载登录路由时,打开控制台看到这个错误信息?
[Vue warn]: Unknown custom element: - did you register the component correctly?
[Vue 警告]:未知的自定义元素:-您是否正确注册了组件? For recursive components, make sure to provide the "name" option.
对于递归组件,请确保提供“名称”选项。
(found in )
(在发现 )
How do I register extra components???我如何注册额外的组件???
// login.blade.php - I have placed this under the closing tag and @endsection to test on the login page...
// login.blade.php - 我已经把它放在结束标签和@endsection 下以在登录页面上测试......
You need an element with the id that you defined in your js/app.js:您需要一个具有您在 js/app.js 中定义的 id 的元素:
const app = new Vue({
el: '#app', // you need an element with id="app". Your vue component will replace this
});
Then put your component inside that element.然后将您的组件放在该元素中。
//login.blade.php //登录.blade.php
@extends('layouts.authentication')
@section('content')
<div id="app">
<example-component2/>
</div>
@endsection
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.