vue手機(jī)端input change時(shí),無(wú)法執(zhí)行的問(wèn)題及解決
vue手機(jī)端input change時(shí)無(wú)法執(zhí)行
vue H5頁(yè)面中,有一個(gè)搜索功能,回車時(shí)執(zhí)行
代碼如下:
<el-input placeholder="請(qǐng)輸入內(nèi)容" prefix-icon="el-icon-search" clearable size="small" v-model="searchVal" @change="search"></el-input>
問(wèn)題
手機(jī)端在搜索時(shí),按如下步驟搜索,會(huì)有偶發(fā)性的不執(zhí)行的情況(打字區(qū)域右下角鍵為 “確認(rèn)”或者“換行”)
- 輸入列表中的某一項(xiàng),如視頻,點(diǎn)擊右下角的確認(rèn)
- 刪除視頻,輸入一些其他文字,再刪除,再輸入,點(diǎn)擊右下角確認(rèn)


當(dāng)加上form后 確認(rèn)或換行 就會(huì)變?yōu)?前往
<form action="">
<el-input placeholder="請(qǐng)輸入內(nèi)容" prefix-icon="el-icon-search" clearable size="small" v-model="searchVal" @change="search"></el-input>
</form>如果該問(wèn)題依舊存在,在搜索時(shí),將光標(biāo)移除
<form action="">
<el-input ref="ipt" placeholder="請(qǐng)輸入內(nèi)容" prefix-icon="el-icon-search" clearable size="small" v-model="searchVal" @change="search"></el-input>
</form>
search () {
this.$refs.ipt.blur()
……
}vue input[type=‘file’] change事件無(wú)法上傳相同文件的問(wèn)題
== 話不多說(shuō),上代碼 ==
html
<input ? ?ref="fileInput" ? ?type="file" ? ?accept="image/*" ? ?style="display: none" ? ?@change="getFile"> <el-button size="mini" type="primary" @click="addLogo">嵌入logo</el-button> <el-button size="mini" @click="removeLogo">撤銷logo</el-button> ??
js
// 嵌入logo
? ? addLogo() {
? ? ? this.$refs.fileInput.click()
? ? },
// 調(diào)用change方法 ? ?
? ? getFile(event) {
? ? ? const files = event.target.files || null
? ? ? const fileReader = new FileReader() // 內(nèi)置方法new FileReader() ? 讀取文件
? ? ? fileReader.addEventListener('load', () => {
? ? ? ? this.imageUrl = fileReader.result
? ? ? ? this.qrCode.clear()
? ? ? ? this.qrCode2.clear()
? ? ? ? this.options2['logo'] = this.imageUrl
? ? ? ? this.options['logo'] = this.imageUrl
? ? ? ? this.qrCode = new QRCode(this.$refs['QRCode'], this.options)
? ? ? })
? ? ? fileReader.readAsDataURL(files[0])
? ? },
? ?// 撤銷logo
? ? removeLogo() {
? ? ? this.options.logo = ''
? ? ? this.options2.logo = ''
? ? ? this.qrCode.clear()
? ? ? this.qrCode2.clear()
? ? ? this.qrCode = new QRCode(this.$refs['QRCode'], this.options)
? ? }, ? ?當(dāng)我點(diǎn)擊嵌入logo,再撤銷logo后,再次嵌入同一張logo時(shí),發(fā)現(xiàn)不起作用,logo沒有嵌入進(jìn)來(lái),后來(lái)明白,是因?yàn)槲覀冊(cè)谇度雔ogo地址后,需要將logo地址清空,以便下次嵌入再次寫入logo圖片路徑,這時(shí):
?getFile(event) {
? ? ? const files = event.target.files || null
? ? ? const fileReader = new FileReader() // 內(nèi)置方法new FileReader() ? 讀取文件
? ? ? fileReader.addEventListener('load', () => {
? ? ? ? this.imageUrl = fileReader.result
? ? ? ? this.qrCode.clear()
? ? ? ? this.qrCode2.clear()
? ? ? ? this.options2['logo'] = this.imageUrl
? ? ? ? this.options['logo'] = this.imageUrl
? ? ? ? this.qrCode = new QRCode(this.$refs['QRCode'], this.options)
? ? ? })
? ? ? fileReader.readAsDataURL(files[0])
? ? ? this.$refs.fileInput.value = null ?//我們需要加一個(gè)把當(dāng)前文件路徑清空的方法
? ? },總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
uniapp中使用u-loadmore,loadText內(nèi)容不隨status改變刷新方式
這篇文章主要介紹了uniapp中使用u-loadmore,loadText內(nèi)容不隨status改變刷新方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-05-05
Vue項(xiàng)目導(dǎo)入導(dǎo)出文件功能以及導(dǎo)出文件后亂碼問(wèn)題及解決
這篇文章主要介紹了Vue項(xiàng)目導(dǎo)入導(dǎo)出文件功能以及導(dǎo)出文件后亂碼問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-09-09
Vue中使用create-keyframe-animation與動(dòng)畫鉤子完成復(fù)雜動(dòng)畫
這篇文章主要介紹了Vue中使用create-keyframe-animation與動(dòng)畫鉤子完成復(fù)雜動(dòng)畫,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-04-04
vue如何在vue.config.js文件中導(dǎo)入模塊
這篇文章主要介紹了vue如何在vue.config.js文件中導(dǎo)入模塊問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-07-07
vue3-reactive定義的對(duì)象數(shù)組如何賦值
這篇文章主要介紹了vue3-reactive定義的對(duì)象數(shù)組如何賦值問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2025-06-06
Vue實(shí)現(xiàn)頁(yè)面返回停留原位置的多種方案
文章主要討論了在 Vue 開發(fā)中實(shí)現(xiàn)頁(yè)面返回停留原位置的多種方案,包括 Vuex、keep-alive、v-show、客戶端跳轉(zhuǎn)等,并分別闡述了它們的優(yōu)缺點(diǎn)和適用情況,強(qiáng)調(diào)開發(fā)前應(yīng)周全考慮前端業(yè)務(wù)和用戶體驗(yàn),根據(jù)實(shí)際業(yè)務(wù)選擇合適方案,需要的朋友可以參考下2025-03-03
vue使用vuex實(shí)現(xiàn)首頁(yè)導(dǎo)航切換不同路由的方法
這篇文章主要介紹了vue使用vuex實(shí)現(xiàn)首頁(yè)導(dǎo)航切換不同路由的方法 ,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-05-05
vue2 router 動(dòng)態(tài)傳參,多個(gè)參數(shù)的實(shí)例
下面小編就為大家?guī)?lái)一篇vue2 router 動(dòng)態(tài)傳參,多個(gè)參數(shù)的實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-11-11

