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