文章詳情頁
javascript - 關(guān)于vuejs讀取數(shù)據(jù)的問題
瀏覽:111日期:2022-11-12 14:36:14
問題描述
如圖所示,用vuejs寫了一個發(fā)帖子的小小demo,但現(xiàn)在只能讀取post里面的img字段,如何把全部字段讀取出來?
html代碼
js代碼
問題解答
回答1: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})// 同時在最后把post清空Object.keys(vm.newPost).forEach(item => vm.newPost[item] = ’’)回答2:
數(shù)據(jù)不是已經(jīng)在this.newPost 里面了么?
你通過v-model把this.newPost的數(shù)據(jù)跟dom綁定在一起了,不去this.newPost里面拿,反而從dom里獲取數(shù)據(jù)?
標簽:
JavaScript
相關(guān)文章:
1. javascript - 百度echarts series數(shù)據(jù)更新問題2. mysql - 一個表和多個表是多對多的關(guān)系,該怎么設(shè)計3. python - type函數(shù)問題4. php - 第三方支付平臺在很短時間內(nèi)多次異步通知,訂單多次確認收款5. Mysql && Redis 并發(fā)問題6. css3 - css before 中文亂碼?7. mysql新建字段時 timestamp NOT NULL DEFAULT ’0000-00-00 00:00:00’ 報錯8. css3 - 手機網(wǎng)頁中用css寫1px的描邊,為什么需要加一句overflow:hidden才能真正顯示1px?9. javascript - node服務(wù)端渲染的困惑10. css - 求推薦幾款好用的移動端頁面布局調(diào)試工具呢?
排行榜

熱門標簽