js fetch方法使用
// get請求,第一個參數是請求地址,第二個可選,默認發送的是get請求 fetch('/api/user/list').then(res => { res.json().then(data => { console.log(data); // 獲取數據 }) })
// 發送post請求
fetch('/api/user/list', { method: 'POST', headers: { 'Content-Type': 'application/json' //指定請求頭 }, body: JSON.stringify({}) // 請求參數,需要用JSON.stringify轉換 }).then(res => { res.json().then(data => { console.log(data); // 獲取數據 }) })