Skip to content

fetch

访问白马指南。

document.getElementById("run").addEventListener("click", run);

async function run() {
  await Excel.run(async (context) => {
    const response = await fetch("https://www.baima.site/");
    const text = await response.text();
    console.log(text);
  });
}
<button id="run">Run</button>

访问 AirTable 。

const TOKEN = '123456';
const BASE_ID = 'app123456';
const TABLE_NAME = 'kv';

document.getElementById("run").addEventListener("click", run);

async function run() {
  await Excel.run(async (context) => {
    const url = 'https://api.airtable.com/v0/' + BASE_ID + '/' + TABLE_NAME;
    const options = { method: 'GET', headers: { Authorization: 'Bearer ' + TOKEN } };

    try {
      const response = await fetch(url, options);
      const data = await response.json();
      console.log(data.records);
    } catch (error) {
      console.error(error);
    }
  });
}

联系 math@baima.site