传统的url参数写法:
fetch('/abc?id=123').then(data => {
//默认是get
//得到的是一个promise对象,用于获取后台返回的数据
return data.text();
}).then(ret => {
//这里才是得到的最终数据
console.log(ret);
})
//后台接收参数为req.query.id
Restful形式的url参数写法:
fetch('/abc/123',{
method:'get'
}).then(data => {
return data.text();
}).then(ret => {
//这里才是得到的最终数据
console.log(ret);
})
//:id
//后台接收参数为req.params.id