首页 >社区问答列表 >javascript - 关于vuejs读取数据的问题

javascript - 关于vuejs读取数据的问题

如图所示,用vuejs写了一个发帖子的小小demo,但现在只能读取post里面的img字段,如何把全部字段读取出来?

html代码

js代码

  • 小葫芦
  • 小葫芦    2017-06-24 09:45:382楼

    1. FileReader 用于本地读取文件的,一般只适用于<input type="file"></input>

    2. 而你的title和content与FileReader没什么关系。它们只受到你data()中的newPost影响。所以你可以在creatPost里面的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
  • phpcn_u1582    2017-06-24 09:45:381楼

    数据不是已经在this.newPost 里面了么?

    你通过v-model把this.newPost的数据跟dom绑定在一起了,不去this.newPost里面拿,反而从dom里获取数据?

    +0添加回复

  • 回复