首页 > 解决方案 > JavaScript + 火力基地。如何使用 fetch for farebase 实现请求,以便删除 farebase 中的项目

问题描述

API_BASE = `https://dims.firebaseio.com/`;
editResource = async (url, body) => {
    const res = await fetch(`${this.API_BASE}${url}`, {
      method: 'PUT',
      body: JSON.stringify(body),
    });
    return await res.json();
}
editMember = async (memberId, body) => {
    return await this.editResource(`/UserProfile/${memberId}`, body);
}
delResource = async (url) => {
    await fetch(`${this.API_BASE}${url}`, {
      method: 'DELETE',
    })
      .then(response => response.json());
};
delMember = async (memberId) => {
    return await this.delResource(`/UserProfile/${memberId}`);
};

结果: 选项:405(不允许方法)访问从源“ http://localhost:3000 ”获取的“ https://dims.firebaseio.com//UserProfile/-M0r1o70-G2JMzQYXbm1 ”已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:它没有 HTTP ok 状态。

标签: javascriptfirebasefirebase-realtime-databasepromisefetch

解决方案


推荐阅读