扫码关注官方订阅号
如图所示,用vuejs写了一个发帖子的小小demo,但现在只能读取post里面的img字段,如何把全部字段读取出来?
html代码
js代码
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] = '')
数据不是已经在this.newPost 里面了么?
this.newPost
你通过v-model把this.newPost的数据跟dom绑定在一起了,不去this.newPost里面拿,反而从dom里获取数据?
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
FileReader 用于本地读取文件的,一般只适用于
<input type="file"></input>而你的title和content与FileReader没什么关系。它们只受到你
data()中的newPost影响。所以你可以在creatPost里面的vm.post.push({img: this.result})改为数据不是已经在
this.newPost里面了么?你通过v-model把
this.newPost的数据跟dom绑定在一起了,不去this.newPost里面拿,反而从dom里获取数据?