我正在使用vue
@keyup
axios
电话:
<template>
<div>
<input type="text" placeholder="Where are you from?" v-model="from" @keyup="getPlace">
<ul>
<li v-for="place in places">{{ place.name }}<li>
</ul>
</div>
</template>
<script>
export default {
data() {
return {
places: [],
from: ''
}
},
methods() {
if(this.from.length <= 3) { this.places = []; return; }
getPlace() {
axios.get('/places?name='+this.from).then((res)=>{
this.places = [];
for(var i = 0; i<res.data.length; i++) {
this.places.push(res.data[i]);
}
}).catch((err)=>{console.log(err)});
}
}
};
</script>
现在可以了,但是有一个很大的问题,每次调用它都会更新一个位置数组,但是时间很晚,所以方法被调用,数组被返回到[],但是在响应返回之后,它会为每个keyup填充数组(如果您键入的速度很快的话)。。。我正在从jquery前端切换到这个,我从来没有遇到过这样的问题:O