I have a Vue component that requires is a file that is a Vue mixin. The required file is part of the provider package, so I cannot modify this file. I need to get support for notifications from mixin. As a result, I get access to the notifications object and get the number of read notifications to display this score as a computed property. It seems that using this.notifications does not work. How can i do this?
Here is my component:
var base = require('notifications/notifications'); Vue.component('spark-notifications', { mixins: [base], });
Here is the notifications file that was required in the previous component:
module.exports = { props: ['notifications', 'hasUnreadAnnouncements', 'loadingNotifications'], data() { return { showingNotifications: true, showingAnnouncements: false } }, methods: { showNotifications() { this.showingNotifications = true; this.showingAnnouncements = false; }, showAnnouncements() { this.showingNotifications = false; this.showingAnnouncements = true; this.updateLastReadAnnouncementsTimestamp(); }, updateLastReadAnnouncementsTimestamp() { this.$http.put('/user/last-read-announcements-at') .then(() => { this.$dispatch('updateUser'); }); } }, computed: { activeNotifications() { if ( ! this.notifications) { return []; } if (this.showingNotifications) { return this.notifications.notifications; } else { return this.notifications.announcements; } }, hasNotifications() { return this.notifications && this.notifications.notifications.length > 0; }, hasAnnouncements() { return this.notifications && this.notifications.announcements.length > 0; } } };
Beginning of the Laravel blade template:
<spark-notifications :notifications="notifications" :has-unread-announcements="hasUnreadAnnouncements" :loading-notifications="loadingNotifications" inline-template>
Here is the method in spark.js that receives notifications:
data: { user: Spark.state.user, teams: Spark.state.teams, currentTeam: Spark.state.currentTeam, loadingNotifications: false, notifications: null, supportForm: new SparkForm({ from: '', subject: '', message: '' }) }, getNotifications() { this.loadingNotifications = true; this.$http.get('/notifications/recent') .then(response => { this.notifications = response.data; this.loadingNotifications = false; }); },
And this is where everything loads together app.js :
require('spark-bootstrap'); require('./components/bootstrap'); var app = new Vue({ mixins: [require('spark')] });