How to validate Vuetify text field asynchronously?

后端 未结 2 1717
走了就别回头了
走了就别回头了 2021-02-09 01:42

Text fields in Vuetify have rules props, which take an array of functions returning true or an error string. How to make them async, so that the valida

2条回答
  •  青春惊慌失措
    2021-02-09 01:42

    One solution is to set the error-messages prop:

    and use the watch option:

    new Vue({
      data () {
        return {
          input: '',
          errors: []
        }
      },
      watch: {
        input (val) {
            axios.get('/check?value=' + val).then(valid => {
              this.errors = valid ? [] : ['async error']
            })
        }
      }
    });
    

提交回复
热议问题