1
我想在VueJs
建立一个小型应用程序, 以下是我的数据集:在那里我有在爱可信通话如何Object元素推到一个数组中Vuejs/JavaScript的
data(){
return {
pusher: '',
channel:'',
notify: [],
notifications: '',
notificationsNumber: '',
}
},
组件的创建属性:
axios.get('api/notifications', {headers: getHeader()}).then(response => {
if(response.status === 200)
{
this.notify = response.data.notifications
this.notificationsNumber = this.notify.length
}
}).catch(errors => {
console.log(errors);
})
我有pusherJs
实现的,所以我有下面的代码:
this.pusher = new Pusher('xxxxxxxx', {
cluster: 'ap2',
encrypted: true
});
var that = this
this.channel = this.pusher.subscribe('stellar_task');
this.channel.bind('company_info', function(data) {
console.log(data.notification);
that.notifications = data.notification
});
一旦被从推杆获得的价值我想这推到我的阵列作为通知手表的财产,是这样的:
watch: {
notifications(newValue) {
this.notify.push(newValue)
this.notificationsNumber = this.notificationsNumber + 1
}
}
所以,问题是,我通过推接收数据格式在对象的形式和推送功能未在此得到实施:
截图:
帮我解决这个问题。
你能'的console.log(this.notify)'内'watch'?如果它是一个'array',它必须有'push'。 – shotor
@morgh是对的,'this.notify'看起来不是一个数组。 – MatWaligora
@MatWaligora我已经将它定义为数据集中的数组,我不知道发生了什么,但是在做console.log的时候我得到了答案。 –