我这样做是为了学习React工具包:
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
export const getIPv4AddressApi = createApi({
reducerPath: "getIPv4Address",
baseQuery: fetchBaseQuery({
baseUrl: "https://ip4.8n1.org/",
}),
endpoints: builder => ({
getIPv4Address: builder.query<string, void>({
query: () => "",
}),
}),
});
export const { useGetIPv4AddressQuery } = getIPv4AddressApi;
运行时,我收到错误
{"status":"PARSING_ERROR","originalStatus":200,"data":"xxx.xxx.xxx.xxx\n","error":"SyntaxError: Unexpected token . in JSON at position 6"}
我怎样才能返回整个响应而不尝试JSON解析呢?非常感谢
2条答案
按热度按时间pkwftd7m1#
请参见解析响应
5gfr0r5j2#
而不是离开查询:作为空字符串,您可以指定数据格式。下面是一个示例:enter image description here