如何解决如何在VueJs中使用新的div推送文本?
有人可以帮我设置这个吗?每当有人发布文字时,我都试图创建一个新的div。基本上像facebook newsFeed post。我做错了,我不知道是什么。 .postSender是否需要v-for或v-if?
.wrapper
.msgSender
.msgSenderTop
img.avatar(src='https://www.w3schools.com/howto/img_avatar.png')
form
input#fname(type='text',v-model="newPost" placeholder="Whats on your mind?")
input.submit(type='submit',value='Submit' @click="sendPost")
.postSender
.postSednerTop
img.avatar(src='https://www.w3schools.com/howto/img_avatar.png')
.infos
h3 Your name
p Timestamp
hr
.postSenderBody
.msg
p {{ placeText.post }}
export default {
name: "Home",data() {
return {
placeText: [{ post: ''}],newPost: ''
}
},methods: {
sendPost() {
this.placeText.push(this.newPost);
this.newPost = '';
}
解决方法
如果我理解正确,则希望用户允许添加多个帖子,并希望在下面显示它们。
第一次更改此邮政编码。
export default {
name: "Home",data() {
return {
placeText: [{ post: ''}],newPost: ''
}
},methods: {
sendPost() {
this.placeText.push(this.newPost);
this.newPost = '';
}
}
您已将placeText
声明为array
的{{1}},但是在objects
方法中,您尝试将文本推入数组,因此当您尝试获取使用sendPost
的文字,您将得到placeText.post
将undefined
方法更改为此
sendPost
现在,您可以在模板部分中遍历这样的帖子数组。
sendPost() {
this.placeText.push({ post: this.newPost })
this.newPost = ''
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。