我如何解决在vuejs中推送实时通知的错误?

我正在尝试使用laravel&vuejs中的pusher进行实时通知,laravel中的ecery东西可以正常工作,数据已在控制台上显示,但是当我尝试将其推入vuejs的数据时出现此错误:

app.js:17310 Uncaught TypeError: _this.unreadNotifications.push is not a function
at app.js:17310
at PrivateChannel.Dispatcher.emit (app.js:100681)
at PrivateChannel.Channel.handleEvent (app.js:101538)
at app.js:103603
at ConnectionManager.Dispatcher.emit (app.js:100681)
at message (app.js:102069)
at Connection.Dispatcher.emit (app.js:100681)
at message (app.js:101238)
at TransportConnection.Dispatcher.emit (app.js:100681)
at TransportConnection.onMessage (app.js:100809)
at WebSocket.socket.onmessage (app.js:100826)

这是我的代码


    export default {
      props :['unreads','userid'],
      data () {
        return {
          unreadNotifications: this.unreads,
        }
      },
      methods:{
          MarkNotificationAsRead() {
              if(this.unreadNotifications.length) {
                  axios.post('/markAsRead')
              }
          }
      },
      mounted() {
          Echo.private('App.User.'+ this.$store.getters.currentUser.id)
             .notification((notification) => {
                  console.log(notification);
                  let newUnreadNotifications= {
                      data: { 
                          idprojet: notification.idprojet, 
                          user: notification.user, 
                          projet: notification.projet, 
                          idrec: notification.idrec, 
                          type: notification.type, 
                          typeNotification: notification.typeNotification, 
                          idTask: notification.idTask, 
                          task: notification.task
                      }
                  };
                  this.unreadNotifications.push(newUnreadNotifications);
                  //document.getElementById("notify_audio").play();
              });
        }
    }
</script>
评论