6. TS

6. TS

明廷盛 嘻嘻😁

1. Fetch发GET/POST请求

  • 发送GET请求
// GET 发送到`https://www.bing.com/search?q=typescript`
// 拼接问号: URLSearchParams
const params = new URLSearchParams({
q: 'typescript',
});
const res = await fetch(`https://www.bing.com/search?${params}`, {
method: 'GET',
headers: { 'Accept': 'application/json' }
});
const data = await res.json(); // 获取结果
  • 发送POST请求
// POST
const res = await fetch('/api/data', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ msg: 'hello' })
});
const data = await res.json();

  • Title: 6. TS
  • Author: 明廷盛
  • Created at : 2026-06-19 12:07:14
  • Updated at : 2026-06-19 17:52:00
  • Link: https://blog.20040424.xyz/2026/06/19/😼Java全栈工程师/7. 前端部分/6. TS/
  • License: All Rights Reserved © 明廷盛
On this page
6. TS