用于 bootstrap-vue 输入编号 Vue.js 的 MaxLength

Beu*_*biu 3 javascript vue.js vue-component vuejs2 bootstrap-vue

我尝试为maxLength来自 的输入实现 a bootstrap-vue,但是从我从他们的文档中读取的内容来看,他们不支持 max. 如果我删除type="number",它可以工作,但不再是一个数字。

    <b-form-input
        size="sm"
        v-model="register_volume_first"
        type="number"
        maxlength=4
        placeholder="1902"
    ></b-form-input>
Run Code Online (Sandbox Code Playgroud)

Bou*_*him 8

尝试使用formatterprop 如下:

<template>
  <div>
    <b-form-input size="sm" v-model="volume" type="number" :formatter="formatYear" placeholder="1902"></b-form-input>
       <div class="mt-2">Value: {{ volume }}</div>
  </div>
</template>

<script>
  export default {
    data() {
      return {
       volume: '4'
      }
    },
methods:{
  formatYear(e){
     return String(e).substring(0,4);
  }
}
  }
</script>
Run Code Online (Sandbox Code Playgroud)