首页 > 解决方案 > 需要帮助使用 Vuex 使用 Firebase Rest API 发送 DELETE 请求

问题描述

我正在尝试从 firebase 中删除一些信息,但在使其正常工作时遇到了一些麻烦。

我想要做的是让 deleteRequest 按钮删除从获取链接中提取的数据。

这是按钮和方法

<div class="actions">
  <base-button @click="deleteRequest">Delete</base-button>
  </div>

async deleteRequest() {
  await this.$store.dispatch('requests/deleteRequest', {
    email: this.email,
    message: this.message,
    artistId: this.$route.params.id,
  });

async deleteRequest(context, payload) {
    const removeRequest = {
        userEmail: payload.email,
        message: payload.message
    };
    const response = await fetch(`https://find-artist-d3495-default-rtdb.firebaseio.com/requests/${payload.artistId}.json`, {
        method: 'DELETE',
        body: JSON.stringify(removeRequest)
    });

    const responseData = response.json();

    if (!response.ok) {
        const error = new Error(responseData.message || 'Failed to send request.');
        throw error;
    }
    context.commit('deleteRequests', removeRequest);
},

标签: javascriptfirebasevue.jsfirebase-realtime-databasevuex

解决方案


推荐阅读