mirror of
https://gitee.com/ant-design-vue/ant-design-vue.git
synced 2024-12-04 21:18:14 +08:00
36 lines
714 B
JavaScript
36 lines
714 B
JavaScript
|
|
import jsonp from 'jsonp'
|
|
import querystring from 'querystring'
|
|
let timeout
|
|
let currentValue
|
|
|
|
export function fetch (value, callback) {
|
|
if (timeout) {
|
|
clearTimeout(timeout)
|
|
timeout = null
|
|
}
|
|
currentValue = value
|
|
|
|
function fake () {
|
|
const str = querystring.encode({
|
|
code: 'utf-8',
|
|
q: value,
|
|
})
|
|
jsonp(`http://suggest.taobao.com/sug?${str}`, (err, d) => { // eslint-disable-line
|
|
if (currentValue === value) {
|
|
const result = d.result
|
|
const data = []
|
|
result.forEach((r) => {
|
|
data.push({
|
|
value: r[0],
|
|
text: r[0],
|
|
})
|
|
})
|
|
callback(data)
|
|
}
|
|
})
|
|
}
|
|
|
|
timeout = setTimeout(fake, 300)
|
|
}
|