vue input 或 el-input type=“number” 输入数字,去除右侧箭头
一、具体问题为:input或者el-input中添加type=number来控制只可输入数字。但随之而来的问题是 输入框右侧会有个上下调整箭头二、解决方法:2.1、input常用的解决方法,实际是将控制显示箭头的 css样式去掉,但少部分会不好用,因此可以添加个class来指定。不过对于el-input此方法仍然不好用<template><Input v-model="value
一、具体问题为:
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>
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/的支持,不知道为啥现在最新的还是会有?
更多推荐
所有评论(0)