Guys, how do you restrict input to enter numbers only in vue?

guys, how do you limit input to entering numbers in vue? Vue-cli built the project, the introduction of the iview UI framework.

Mar.13,2021

you can refer to the following. At present, this is a limit. You can only enter numbers, keep only 2 decimal places, and cannot enter spaces.

<div id="app">
    <input type="text" v-model="a" @input="change(a)" /> 
</div>
<script src="https://cdn.bootcss.com/vue/2.6.10/vue.js"></script>
<script type="text/javascript">
    new Vue({
        el: "-sharpapp",
        data: {
            a: ""
        },
        methods: {
            change(val) {
                val = val.replace(/(^\s*)|(\s*$)/g, "")
                if(!val) {
                    this.a = "";
                    return
                }
                var reg = /[^\d.]/g

                // 
                val = val.replace(reg, "")

                // 
                val = val.replace(/^\./g, "");
                // 1
                val = val.replace(".", "$-sharp$").replace(/\./g, "").replace("$-sharp$", ".");
                // 2
                val = val.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');

                this.a = val;
            }
        }
    })
</script>

v-model.number


input limit array, don't you set number by type in input?

or according to the official website
< input vmurmodel.number = "age" type= "number" >

Link: ide/forms.html-sharpnumber" rel=" nofollow noreferrer "> https://cn.vuejs.org/v2/guide.


Vue Native Writing rules replace what you need now the limit is that you can only enter numbers

<input type="text" v-model="_msg">
//////////////////////////
<script>
export default {
  name: "auth",
  data(){
    return {
      msg:''
    }
  },
  computed: {
    _msg: {
      set: function(value) {
          this.msg = value;
      },
      get: function() {
          return this.msg.replace(/[^0-9]+/g,'')
      }
    }
  }
};
</script>
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b37a6c-e5fe.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b37a6c-e5fe.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?