打赏

element之input输入搜索联想框

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);
            },

 

posted on 2019-10-30 22:44  jlyuan  阅读(2455)  评论(0编辑  收藏  举报

导航