问题:当搜狗输入法开启时,扫码枪输入,会带出输入法的输入框

前置条件

扫码枪输入

<!-- 点击事件触发 -->
<el-tag @click="scodeClick">点击扫码</el-tag> 
<!-- 弹窗监听输入 -->
<div class="popCodeBox" v-if="showCode" @click="outCodeClick">
    <i class="icon-code el-icon-full-screen"></i>
    <el-input class="opa" ref="codeInput" v-model="codeStr"  @change="codeChange" @blur="codeBlur" />
</div>
scodeClick() {
   this.showCode = true;
},
codeChange(val) { // 监听input输入
    console.log(val, '获取二维码内容')
},
codeBlur() { // input 失焦
   this.showCode = false;
},
outCodeClick() { // 点击关闭弹窗
  this.showCode = false;
 },
<style>
.popCodeBox {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, .6);
    z-index: 9;
}

.popCodeBox .opa {
    /* 隐藏输入框 */
    position: fixed;
    left: 0;
    top: -9999px;
}

.popCodeBox .opa .el-input__inner {
    filter: alpha(opacity=0);
    /* IE */
    -moz-opacity: 0;
    /* 老版Mozilla */
    -khtml-opacity: 0;
    /* 老版Safari */
    opacity: 0;
    /* 支持opacity的浏览器*/
    ime-mode: disabled;
}

.popCodeBox .icon-code {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #fff;
    font-size: 200px;
    z-index: 9;
}

.popCodeBox .icon-code::after {
    content: '';
    position: absolute;
    left: 0;
    width: 200px;
    height: 10px;
    background-color: #0079fe;
    border-radius: 10px;
    animation: fadenum 2s linear infinite;
}

@keyframes fadenum {
    0% {
        transform: translateY(20px);
    }

    100% {
        transform: translateY(160px);
    }
}
</style>

过程

1.一开始以为是样式opacity不兼容导致扫码录入时有输入框显示,做了浏览器兼容
filter:alpha(opacity=0); /* IE /
-moz-opacity:0; /
老版Mozilla /
-khtml-opacity:0; /
老版Safari /
opacity: 0; /
支持opacity的浏览器*/
2.测试后发现还是存在问题,才发现时搜狗输入法原因,改了input的类型 type=“password”,直接忽略输入问题(也防止中文输入导致码不对)

<el-input class="opa" ref="codeInput" v-model="codeStr" type="password" @change="codeChange" @blur="codeBlur"/>

3.再次测试发现,因为input是密码类型,所以浏览器触发保存密码,新增了autocomplete=“new-password”,解决了这个问题

<el-input class="opa" ref="codeInput" v-model="codeStr" type="password" autocomplete="new-password" @change="codeChange" @blur="codeBlur"/>

最终代码

<template>
    <div>
        <!-- 点击事件触发 -->
        <el-tag @click="scodeClick">点击扫码</el-tag>
        <!-- 弹窗监听输入 -->
        <div class="popCodeBox" v-if="showCode" @click="outCodeClick">
            <i class="icon-code el-icon-full-screen"></i>
            <el-input class="opa" ref="codeInput" v-model="codeStr" @change="codeChange" @blur="codeBlur" />
        </div>
    </div>
</template>
<script>
export default {
    name: "",
    components: {},
    data() {
        return {
            showCode: false
        }
    },
    methods: {
        scodeClick() {
            this.showCode = true;
        },
        codeChange(val) { // 监听input输入
            console.log(val, '获取二维码内容')
        },
        codeBlur() { // input 失焦
            this.showCode = false;
        },
        outCodeClick() { // 点击关闭弹窗
            this.showCode = false;
        },
    }
}
</script>
<style lang="scss" >
.popCodeBox {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, .6);
    z-index: 9;
}

.popCodeBox .opa {
    /* 隐藏输入框 */
    position: fixed;
    left: 0;
    top: -9999px;
}

.popCodeBox .opa .el-input__inner {
    filter: alpha(opacity=0);
    /* IE */
    -moz-opacity: 0;
    /* 老版Mozilla */
    -khtml-opacity: 0;
    /* 老版Safari */
    opacity: 0;
    /* 支持opacity的浏览器*/
    ime-mode: disabled;
}

.popCodeBox .icon-code {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #fff;
    font-size: 200px;
    z-index: 9;
}

.popCodeBox .icon-code::after {
    content: '';
    position: absolute;
    left: 0;
    width: 200px;
    height: 10px;
    background-color: #0079fe;
    border-radius: 10px;
    animation: fadenum 2s linear infinite;
}

@keyframes fadenum {
    0% {
        transform: translateY(20px);
    }

    100% {
        transform: translateY(160px);
    }
}
</style>

在这里插入图片描述

点击阅读全文
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐