1. 模板代码
<el-autocomplete :minlength="2" v-model="searchName" :fetch-suggestions="querySearchAsync" placeholder="请输入内容" @select="handleSelect"></el-autocomplete>
2. js 代码
querySearchAsync(queryString, cb) { if (queryString && queryString.length > 2) { let params = { name: queryString } this.axios.get("/api/search/name", { params }).then(res => { if (res.data.code == 200) { cb(res.data.data); } }) } }, handleSelect(item) { console.log(this.searchName, item); },