实现效果

UI组件依然是使用 Quasar Framework。

先来看一下效果:

Quasar Input:type="number" 去掉上下小箭头 实现加减按钮样式功能

加减.gif

input type="number" 去掉上下小箭头

去掉上下小箭头,主要是css:

 input::-webkit-outer-spin-button, 
 input::-webkit-inner-spin-button {
 -webkit-appearance: none;
 }

 input[type='number'] {
 -moz-appearance: textfield;
 }

实现加减按钮样式及功能

template:

<div class="row mg">
 <div class="col-5 text-right form-label-sm">
  <span class="number">数字</span>
  <span class="tips">(必填)</span>
 </div>
 <div class="col-6">
  <q-input v-model.number="model" type="number" outlined class="input">
  <template v-slot:prepend>
  <q-btn
  dense
  flat
  icon="remove"
  class="number-btn"
  @click="numberSub(model)"
  />
  </template>
  <template v-slot:append>
  <q-btn
  dense
  flat
  icon="add"
  class="number-btn"
  @click="numberAdd(model)"
  />
  </template>
  </q-input>
 </div>
 </div>

     css:

<style lang="stylus">
.form-label-sm {
 font-weight: 400;
 font-size: 12px;
 line-height: 32px;
 padding-right: 16px;

 .number {
 font-weight: 500;
 font-size: 13px;
 display: block;
 line-height: 18px;
 }

 .tips {
 font-weight: 400;
 font-size: 12px;
 display: block;
 line-height: 13px;
 color: rgba(150, 156, 163, 1);
 }
}

.input {
 width: 200px;

 div {
 height: 32px !important;
 padding: 0 2px;
 }

 div.no-wrap, .q-btn__wrapper {
 padding: 0;
 }

 input::-webkit-outer-spin-button, input::-webkit-inner-spin-button {
 -webkit-appearance: none;
 }

 input[type='number'] {
 -moz-appearance: textfield;
 }

 input {
 text-align: center;
 }

 .number-btn {
 background-color: #f5f7f9;
 border: 1px solid #ccc;
 height: 100%;
 }
}
</style>
data () {
 return {
 model: 10
 }
 }

methods:

 numberAdd (val) {
 // console.log(val)
 val++
 this.model = Number.parseFloat(val)
 },
 numberSub (val) {
 // console.log(val)
 val--
 this.model = Number.parseFloat(val)
 }

完整代码

请查看:Quasar Input:type="number" 去掉上下小箭头 实现加减按钮样式点击预览

总结

广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!