从2014年的发展来展望JS的未来将会如何
<font face="寰�杞�闆呴粦, Arial, sans-serif ">2014骞达紝杞�浠惰�屼笟鍙戝睍杩呴€燂紝鍚勭�嶈��瑷€灞傚嚭涓嶇┓锛屼互婊¤冻鐢ㄦ埛涓嶆柇鍙樺寲鐨勯渶姹傘€傝繖浜涜��...
2015-11-12
有一种场景,在select框改变的时候,不管用户怎么连续操作,我只关心用户最后一次的结果,fetch并不是ajax有abort方法,这里模拟了一种,忽略不需要的请求
<div id="app">
<select @change="_getTitle">
<option v-for="(value, key) in titleId">{{value}}</option>
</select>
<div>{{cont}}</div>
</div>
new Vue({
el: '#app',
data: {
nextSeqid: 0,
baseUrl: 'http://www.liuweibo.cn:7654',
titleId:[192,191,190],
cont: '正在请求。。。'
},
created() {
},
methods: {
_getTitle(e) {
const seqid = ++this.nextSeqid;
console.log(seqid, this.nextSeqid, '请求')
let url = `${this.baseUrl}/api/detail?id=${e.target.value}`;
axios.get(url).then(res => {
let {title} = res.data[0];
console.log(seqid, this.nextSeqid, '请求完成')
if (seqid === this.nextSeqid) {
this.cont = title;
}else {
this.cont='正在请求。。。'
}
})
},
}
})
原文链接:https://segmentfault.com/a/1190000015619385
本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。
转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]