[英]Laravel Vue web-notification component errors
我正在嘗試顯示從組件Vue到layout / app.blade的通知欄,但控制台中發生錯誤。
[Vue警告]:創建的掛鈎中出現錯誤:“ TypeError:無法讀取未定義的屬性'userId'”
和,
TypeError:無法讀取未定義的屬性“ userId”
我的app.js如下所示。
require('./bootstrap');
window.Vue = require('vue');
window._ = require('lodash');
window.$ = window.jQuery = require('jquery');
Vue.component('estate', require('./components/EstateNotification.vue'));
const app = new Vue({
el: '#app',
data: {
estates: '',
},
created(){
if (window.Laravel.userId){
axios.post('/notification/estate/notification').then(response => {
this.estates = response.data;
console.log(response.data)
});
Echo.private('App.User.'+ window.Laravel.userId).notification((response) => {
data = {"data":response};
this.estates.push(data);
console.log(response);
});
}
}
});
在我的路線上:
Route::post('/notification/estate/notification', 'EstateController@notification');
控制器:
public function notification()
{
return auth()->user()->unreadNotifications;
}
但我不知道為什么,為什么userId未定義? 我在哪里做錯了? 真的非常感謝您的幫助!
在app.blade中嘗試一下:
<div id ="app">
<estate v-bind:estates="estates"></estate>
</div>
const app = new Vue({
el: '#app' //this ID
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.