我已经构建了一个带有拦截器的 axios 私有实例来管理身份验证请求。
\n系统有一个自定义的axios实例:
\nconst BASE_URL = 'http://localhost:8000';\nexport const axiosPrivate = axios.create({\n baseURL: BASE_URL,\n headers: {\n 'Content-Type': 'application/json',\n },\n withCredentials: true,\n});\nRun Code Online (Sandbox Code Playgroud)\n自定义 useRefreshToken 挂钩使用刷新令牌返回 accessToken:
\nconst useRefreshToken = () => {\n const { setAuth } = useAuth();\n\n const refresh = async () => {\n const response = await refreshTokens();\n // console.log('response', response);\n const { user, roles, accessToken } = response.data;\n setAuth({ user, roles, accessToken });\n // return accessToken for use in axiosClient\n return accessToken;\n };\n\n return …Run Code Online (Sandbox Code Playgroud) 我正在尝试从gsmarena下载数据。可以从以下站点“ http://www.gsmarena.com/htc_one_me-7275.php ” 下载一个HTC我规范的示例代码,如下所述:
网站上的数据以表格和表格行的形式分类。数据格式为:
table header > td[@class='ttl'] > td[@class='nfo']
Run Code Online (Sandbox Code Playgroud)
Items.py文件:
import scrapy
class gsmArenaDataItem(scrapy.Item):
phoneName = scrapy.Field()
phoneDetails = scrapy.Field()
pass
Run Code Online (Sandbox Code Playgroud)
蜘蛛文件:
from scrapy.selector import Selector
from scrapy import Spider
from gsmarena_data.items import gsmArenaDataItem
class testSpider(Spider):
name = "mobile_test"
allowed_domains = ["gsmarena.com"]
start_urls = ('http://www.gsmarena.com/htc_one_me-7275.php',)
def parse(self, response):
# extract whatever stuffs you want and yield items here
hxs = Selector(response)
phone = gsmArenaDataItem()
tableRows = hxs.css("div#specs-list table")
for tableRows in tableRows:
phone['phoneName'] = tableRows.xpath(".//th/text()").extract()[0]
for ttl in …Run Code Online (Sandbox Code Playgroud) 我一直在尝试使用 Redux 工具包进行身份验证刷新令牌调用,但在安装所有修复程序后,它现在仍然能够读取错误消息。
设置 axios 实例:
export const axiosInstance = axios.create({
baseURL: REACT_APP_API_URL,
});
Run Code Online (Sandbox Code Playgroud)
进行API调用:
export const refreshAccessAndRefreshTokens = async () => {
const response = await axiosInstance({
method: 'post',
url: '/refresh-tokens',
withCredentials: true,
});
return response;
};
Run Code Online (Sandbox Code Playgroud)
thunk函数:
// GET ACCESS TOKEN USING REFRESH TOKEN
export const refreshTokens = createAsyncThunk(
'auth/refreshTokens',
async ({ rejectWithValue }) => {
try {
const response = await refreshAccessAndRefreshTokens();
return response.data;
} catch (error) {
console.log('error', error);
console.log('data', error.response.data);
console.log('message', error.response.data.message);
return rejectWithValue(error.response.data.message);
} …Run Code Online (Sandbox Code Playgroud) 我使用 TipTap 作为我的 React 项目的富文本编辑器,用于更新从下拉列表中选择的产品的描述。
预期结果是编辑器应显示已保存在相应产品数据库中的初始内容。
但是,使用编辑器中的“内容”选项允许我设置初始内容,如果我更改下拉列表中的选项,它不会更新初始内容。
我的编辑器代码:
import { useEditor, EditorContent } from '@tiptap/react';
import StarterKit from '@tiptap/starter-kit';
import Underline from '@tiptap/extension-underline';
import Placeholder from '@tiptap/extension-placeholder';
import TipTapMenubar from './TipTapMenubar';
const TiptapEditor = ({ description, setDescription }) => {
// console.log('description', description);
const sampleDesc = `Describe your product in 4-5 bullet points...
Point #1: this is an explanation of my product.
Point #2: ....`;
const editor = useEditor({
extensions: [
StarterKit,
Underline,
Placeholder.configure({
placeholder: sampleDesc,
}),
],
content: `${description}`, …Run Code Online (Sandbox Code Playgroud) reactjs ×3
next.js ×2
axios ×1
python ×1
react-redux ×1
redux-thunk ×1
scrapy ×1
tiptap ×1
web-scraping ×1