Vue bileşenine sahip bir dosyam var. Gerekli dosya bir satıcı paketinin bir parçası olduğundan, bu dosyayı değiştiremiyorum. Karışımdan notifications
desteğini almam gerekiyor. Sonuç olarak, notifications
nesnesine erişeceğim ve bu sayımı hesaplanmış özellik olarak gösterecek şekilde okuma bildirimlerinin miktarını alacağım. this.notifications
kullanmıyor gibi görünüyor. Bunu nasıl yapabilirim?Veri kaynağından veri alma Vue.js
var base = require('notifications/notifications');
Vue.component('spark-notifications', {
mixins: [base],
});
önceki bileşende gerekti notifications
dosyasıdır: Burada
module.exports = {
props: ['notifications', 'hasUnreadAnnouncements', 'loadingNotifications'],
/**
* The component's data.
*/
data() {
return {
showingNotifications: true,
showingAnnouncements: false
}
},
methods: {
/**
* Show the user notifications.
*/
showNotifications() {
this.showingNotifications = true;
this.showingAnnouncements = false;
},
/**
* Show the product announcements.
*/
showAnnouncements() {
this.showingNotifications = false;
this.showingAnnouncements = true;
this.updateLastReadAnnouncementsTimestamp();
},
/**
* Update the last read announcements timestamp.
*/
updateLastReadAnnouncementsTimestamp() {
this.$http.put('/user/last-read-announcements-at')
.then(() => {
this.$dispatch('updateUser');
});
}
},
computed: {
/**
* Get the active notifications or announcements.
*/
activeNotifications() {
if (! this.notifications) {
return [];
}
if (this.showingNotifications) {
return this.notifications.notifications;
} else {
return this.notifications.announcements;
}
},
/**
* Determine if the user has any notifications.
*/
hasNotifications() {
return this.notifications && this.notifications.notifications.length > 0;
},
/**
* Determine if the user has any announcements.
*/
hasAnnouncements() {
return this.notifications && this.notifications.announcements.length > 0;
}
}
};
laravel bıçak şablonunun başlangıcı:
<spark-notifications
:notifications="notifications"
:has-unread-announcements="hasUnreadAnnouncements"
:loading-notifications="loadingNotifications"
inline-template>
İşte, spark.js
'daki notu alan yöntem budur.
require('spark-bootstrap');
require('./components/bootstrap');
var app = new Vue({
mixins: [require('spark')]
});
: OP böylece gibi çalışan var okunmamış bildirimlerin sayısı, almaya çalışıyordum konsolda. Blade şablonunun başlangıcını sordum, böylece neye benzediğini görebilirsiniz. – dericcain
ve 'bildirimler 'başka bir yerde de tanımlanmış mı? – Jeff
Bu doğru. Aynı Vue örneği ancak bir $ http.get' isteği kullanılarak tamamen farklı bir dosyada. Bildirimleri alan yöntem, 'oluşturulan' yönteminde çağrılır. Oradan benim Vue dosyasına nasıl ulaşacağımı bilmiyorum. Blade dosyamda erişebilirim, ancak bazı hesaplamalar yapmam gerekiyor. – dericcain