vue input 或 el-input type=“number” 输入数字,去除右侧箭头

一、具体问题为:

input或者el-input中添加type=number来控制只可输入数字。
但随之而来的问题是 输入框右侧会有个上下调整箭头
在这里插入图片描述

二、解决方法:

2.1、input

常用的解决方法,实际是将控制显示箭头的 css样式去掉;
但少部分会不好用,因此可以添加个class来指定。

<template>
    <Input v-model="value" placeholder="微信内部号码" type="number" number="true" class="aaaa"  :maxlength="20" clearable style="width:80%;ime-mode:Disabled" @on-keydown="changeaa(event)">
      <span slot="prepend">微信</span>
     </Input>
</template>
<script>
    export default {
        data () {
            return {
                value: ''
            }
        },
      methods:{
        changeaa(event){
            //禁止非数字字符输入
          if(event.keyCode<48||event.keyCode>57)event.returnValue=false;
        }
      }
    }
</script>
<style>
.aaaa input::-webkit-outer-spin-button,
.aaaa input::-webkit-inner-spin-button {
    -webkit-appearance: none;
}
.aaaa input[type="number"] {
    -moz-appearance: textfield;
}
</style>

2.2、el-input

不过对于el-input此方法仍然不好用
其中
v-model.number 使用修饰符.number可以将输入的数据转换为Number类型,否则虽然你输入的是数字.但仍为子串类型
然后我们将type设置为number,但发现 样式设置后,仍不生效。
因此,使用/deep/

<el-form-item label="测试数字编号" prop="departnum_id">
     <el-input v-model.number="deptForm.departnum_id" type="number" class="numrule":min="0" :max="99999" placeholder="11001" />
</el-form-item>

<style lang="css" scoped>
  /deep/.numrule input::-webkit-outer-spin-button,
  /deep/.numrule input::-webkit-inner-spin-button {
    -webkit-appearance: none!important;
  }
  /deep/.numrule input[type="number"]{
    -moz-appearance: textfield;
  }
  </style>

2.3 、/deep/

vue /deep/深度选择器
作用
vue官方是说明deep用法。

为了保证每个组件的css唯一性,避免污染全局或者被全局污染,vue提供了scoped作用域

<style scoped>
.a >>> .b { /* ... */ }
</style>

vue官方对于deep选择器的说明

2.3.1 使用场景

我们知道在vue组件中样式中添加 scoped,那么这个样式就会被设定为只影响这个vue组件内的内容
假定某个vue组件又引用了element-ui 亦或者其他UI组件;
此时 UI不满意element-ui的样式,想要在这个页面微调下element-ui的页面;
但不能影响全局element-ui组件样式。
那么我们就需要使用/deep/ 来穿透scoped。

<style lang="scss" scoped>
.a /deep/ .b {
  ......
  /deep/ .c {
    ....
  }
}
</style>
2.3.2 注意事项

1、由于deep是vue-loader中的标准。并不是现行的 css标准。无论是 vue-cli2 中的static文件夹以及vue-cli3中的public文件夹都是仅仅执行了copy_webpack_plugin 所以两者中的css不能使用/deep/选择器。
2、deep不可以嵌套使用。嵌套使用的话,内层的deep不会被正确打包

& /deep/ .isModify{
  & /deep/  .el-input__inner{
        border-color: #f6dfd4;
        background-color: #fff4ef;
        color: #ff6000;;
    }
}

3、在Chrome浏览器下是没有问题的,但是在其他浏览器上就完全不可行了
因为/deep/选择器这个是chrome浏览器自己的标准,其他浏览器并没有实现这个标准,所以其他浏览器是失效的。
有意思的是,google说会在chrome的63这个版本,移除/deep/的支持,不知道为啥现在最新的还是会有?

  • 9
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值