elementui el-select使用远程搜索单选,输入内容不会触发remote-method


1、template

<el-select v-model="form.test" clearable filterable remote :remote-method="remoteCustName" :loading="loading" @clear="remoteCustName">
</el-select>

2、

<script>
export default {
  data () {
    return {
      form: {
        test: ''
      },
      loading: false
    }
  },
  watch: {
    'form.test': {
      deep: true,
      handler (newVal, oldVal) {
    // 为了不请求多次接口可以加上函数节流,具体方法可以查看 点击查看第四点
        this.inputCustName()
      }
    }
  },
  mounted () {
    this.inputCustName()
  },
  methods: {
    remoteCustName (test) {
      // 实时改变v-model值,才会触发watch监听
      this.form.test = test
    },
    inputCustName (test = '') {
      this.loading = true
      // 接口请求开始
    },
  }
}
</script>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM