今天想尝试下 vue.js ,就拿 V2EX 练手, fetch 不到数据啊, response.status 都是 0 啊,难道是我写错了?最后无奈的直接用了 json 文件...
demo 可以看这里( https://github.com/xwartz/vue-v2ex)
fetch('https://www.v2ex.com/api/topics/latest.json', {
method: 'GET',
headers: {
'Content-Type': 'application/json;charset=UTF-8'
},
mode: 'no-cors'
}).then(res => {
if (res.status >= 200 && res.status < 300) {
return Promise.resolve(res)
} else {
return Promise.reject(new Error(res.statusText))
}
}).then(res => {
return res.json()
}).then(data => {
return data
}).catch(err => {
console.log(err)
})