如圖所示,用vuejs寫了一個(gè)發(fā)帖子的小小demo,但現(xiàn)在只能讀取post里面的img字段,如何把全部字段讀取出來?
html代碼
js代碼
FileReader 用于本地讀取文件的,一般只適用于<input type="file"></input>
而你的title和content與FileReader沒什么關(guān)系。它們只受到你data()
中的newPost影響。所以你可以在creatPost里面的vm.post.push({img: this.result})
改為
vm.post.push({
title: vm.newPost.title,
content: vm.newPost.content,
img: this.result
})
// 同時(shí)在最后把post清空
Object.keys(vm.newPost).forEach(item => vm.newPost[item] = '')
數(shù)據(jù)不是已經(jīng)在this.newPost
里面了么?
你通過v-model把this.newPost
的數(shù)據(jù)跟dom綁定在一起了,不去this.newPost
里面拿,反而從dom里獲取數(shù)據(jù)?
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號(hào)
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://m.miracleart.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)