input box to enter a search element of the association

1. template code

            <el-autocomplete :minlength="2" v-model="searchName" :fetch-suggestions="querySearchAsync" placeholder="请输入内容"
                @select="handleSelect"></el-autocomplete>

2. js Code

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

 

Guess you like

Origin www.cnblogs.com/jlyuan/p/11768532.html