文章詳情頁
javascript - 關于vuejs讀取數據的問題
瀏覽:149日期:2022-11-12 14:36:14
問題描述
如圖所示,用vuejs寫了一個發帖子的小小demo,但現在只能讀取post里面的img字段,如何把全部字段讀取出來?
html代碼
js代碼
問題解答
回答1:FileReader 用于本地讀取文件的,一般只適用于<input type='file'></input>
而你的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] = ’’)回答2:
數據不是已經在this.newPost 里面了么?
你通過v-model把this.newPost的數據跟dom綁定在一起了,不去this.newPost里面拿,反而從dom里獲取數據?
標簽:
JavaScript
相關文章:
1. linux - 編譯時提示頭文件#include <mysql/mysql.h>不存在,百度之后也沒解決2. html頁面中怎么將兩個點之間的距離用直線連接起來?3. html - 內嵌app 的web 頁面如何應用 app 內置的靜態文件4. javascript - immutable配合react提升性能?5. JAVA 版本問題?6. node.js - webpack --watch以后報錯env: node: No such file or directory7. java - Spring +Mybatis 事務 不能回滾8. css3 - 如何出現橫向捲軸?9. PHP類中的$this10. javascript - 請教如何獲取百度貼吧新增的兩個加密參數
排行榜
