我如何在 laravel blade 中使用 vuejs 组件?
how i can use vuejs component in laravel blade?
我的想法是在文件中使用 vue 组件 blade 但我遇到了这个错误
Failed to mount component: template or render function not defined.
这是我在 app.js
中的输入
Vue.component('Notification' ,require('./components/Notification.vue'));
这是我的组件代码
<template>
<li class="nav-item dropdown">
<a class="nav-link" data-toggle="dropdown" href="#">
<i class="fas fa-bell"></i> <span class="badge badge-light">{{unreads.length}}</span>
<span class="badge badge-warning navbar-badge"></span>
</a>
<div class="dropdown-menu dropdown-menu-lg dropdown-menu-right">
<notification-item> </notification-item>
</div>
</li>
</template>
<script>
export default {
props :['unreads','userid'],
mounted() {
Echo.private('App.User.'+ this.userid)
.notification((notification) => {
console.log(notification);
});
}
}
</script>
最后这是我在 home.blade.php
中的代码
<Notification :userid="{{auth()->id()}}" :unreads="{{auth()->user()->unreadNotifications}}"> </Notification>
谁能帮帮我
通过 npm run dev
编译 vuejs 文件并确保为 userid
使用正确的绑定并将 app.js 包含到脚本中。
我的想法是在文件中使用 vue 组件 blade 但我遇到了这个错误
Failed to mount component: template or render function not defined.
这是我在 app.js
中的输入Vue.component('Notification' ,require('./components/Notification.vue'));
这是我的组件代码
<template>
<li class="nav-item dropdown">
<a class="nav-link" data-toggle="dropdown" href="#">
<i class="fas fa-bell"></i> <span class="badge badge-light">{{unreads.length}}</span>
<span class="badge badge-warning navbar-badge"></span>
</a>
<div class="dropdown-menu dropdown-menu-lg dropdown-menu-right">
<notification-item> </notification-item>
</div>
</li>
</template>
<script>
export default {
props :['unreads','userid'],
mounted() {
Echo.private('App.User.'+ this.userid)
.notification((notification) => {
console.log(notification);
});
}
}
</script>
最后这是我在 home.blade.php
中的代码<Notification :userid="{{auth()->id()}}" :unreads="{{auth()->user()->unreadNotifications}}"> </Notification>
谁能帮帮我
通过 npm run dev
编译 vuejs 文件并确保为 userid
使用正确的绑定并将 app.js 包含到脚本中。