我正试图在javascript上使用GET方法从URL获取数据,
fetch('/api/staffattendance/{makedate}')
.then(res => res.json())
.then(res => {
//this.staffs = res.data;
console.log(res.data);
})
.catch(err => console.log(err));
我怎么能在这里传递变量
fetch('/api/staffattendance/{makedate}')
像这样
提前致谢,
您是否包含了整个URL(在'1'键左侧的这些小家伙)围绕您的JavaScript使用这个${your-variable}
?
fetch('/api/staffattendance/'+makedate+'')
简单的连接对我来说就像这样
你也可以将te字符串放在这些符号``中,然后在你需要变量的地方加上$ {yourVariable},例如:
fetch(`/api/staffattendance/${makedate}`)
.then(res => res.json())
.then(res => {
//this.staffs = res.data;
console.log(res.data);
})
.catch(err => console.log(err));