距开课0天0时0分-9647937秒
扔个三星炸死你2017-06-24 09:43:38 0 2 309
[HTML讨论组]举报回复话题 ↕
如图所示,用vuejs写了一个发帖子的小小demo,但现在只能读取post里面的img字段,如何把全部字段读取出来?
html代码
js代码
2
0
分享
小葫芦 2017-06-24 09:45:382楼
FileReader 用于本地读取文件的,一般只适用于<input type="file"></input>
<input type="file"></input>
而你的title和content与FileReader没什么关系。它们只受到你data()中的newPost影响。所以你可以在creatPost里面的vm.post.push({img: this.result})改为
data()
vm.post.push({img: this.result})
vm.post.push({ title: vm.newPost.title, content: vm.newPost.content, img: this.result }) // 同时在最后把post清空 Object.keys(vm.newPost).forEach(item => vm.newPost[item] = '')
赞 +0添加回复
phpcn_u1582 2017-06-24 09:45:381楼
数据不是已经在this.newPost 里面了么?
this.newPost
你通过v-model把this.newPost的数据跟dom绑定在一起了,不去this.newPost里面拿,反而从dom里获取数据?
小葫芦 2017-06-24 09:45:382楼
FileReader 用于本地读取文件的,一般只适用于
<input type="file"></input>
而你的title和content与FileReader没什么关系。它们只受到你
data()
中的newPost影响。所以你可以在creatPost里面的vm.post.push({img: this.result})
改为 赞 +0添加回复
phpcn_u1582 2017-06-24 09:45:381楼
数据不是已经在
this.newPost
里面了么?你通过v-model把
this.newPost
的数据跟dom绑定在一起了,不去this.newPost
里面拿,反而从dom里获取数据? 赞 +0添加回复