【发布时间】:2019-12-24 07:26:47
【问题描述】:
我有一个博客 cmets,我试图使用来自套接字服务器的数据添加评论,但是当数据到达客户端并尝试将其推送到我的评论属性时,我的控制台中出现此错误说
vue.js:634 [Vue warn]: $attrs is readonly.
found in
---> <RouterLink>
<Single Post> at resources/assets/guest/views/Single Post.vue
<App> at resources/assets/guest/App.vue
<Root>
<template>
<!-- post comments -->
<div class="section-row">
<div class="section-title">
<h3 class="title">{{comments.length}} Comment<span v-if="comments.length > 1">s</span></h3>
</div>
<div class="post-comments">
<!-- comment -->
<div class="media" v-for="comment in comments">
<div class="media-left">
<img class="media-object" src="/blog/img/avatar-2.jpg" alt="">
</div>
<div class="media-body">
<div class="media-heading">
<h4>{{comment.user.name}}</h4>
<span class="time">{{comment.created_at | dateFromNow}}</span>
</div>
<p>{{comment.body}}</p>
<a href="#" class="reply">Reply</a>
<post-reply :replies="comment.replies"/>
</div>
</div>
<!-- /comment -->
</div>
</div>
<!-- /post comments -->
</template>
export default {
sockets: {
comment_added(comment) {
this.comments.push(comment);
},
},
props : {
postComments : {
type : Array,
required : true
}
},
data : ()=>({
comments : []
}),
watch : {
postComments : function(val){
this.comments = val;
}
},
}
我全局使用vue-socket,并成功连接到socket服务器。但是当我尝试从套接字服务器发出 comment_added 时,就会发生错误。
输出似乎正确。它成功推送了新评论,但在我的控制台中查看错误只是很烦人。
【问题讨论】:
-
错误引用了
router-link内的Single Post.vue。我在您发布的代码中没有看到router-link,所以我猜这不是Single Post.vue? -
那个组件是comment.vue。该错误仅在从套接字服务器发出事件后发生。我没有更改与路由器链接的数据绑定上的任何内容
-
你排除了这个吗? stackoverflow.com/questions/49936163
-
我已经读过了,但他们的解决方案似乎不适用于我的问题
标签: vue.js socket.io vue-component