我尝试使用 Axios 调用 React app(TSX) 和 API(这是我第一次使用 Axios),每次运行应用程序时,方法都会更改为“选项”并且请求变得无效。帮助将不胜感激。分享我的代码抱歉,出于安全原因,我隐藏了身份验证令牌。
代码
import React, { useState, useEffect } from 'react';
import axios from 'axios';
interface Brands {
BrandId: number;
Name: string;
}
const AUTH_TOKEN = Something hiden for security;
var baseUrl = axios.defaults.baseURL = 'https://fppdirectapi-prod.fuelpricesqld.com.au/Subscriber/GetCountryBrands?countryId=21';
axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
axios.defaults.headers.get['Content-Type'] = 'application/json';
axios.defaults.method = 'get';
const FetchFuelType = () => {
const [brands, setPosts] = useState<Brands[]>([]);
useEffect(() => {
axios.get(baseUrl)
.then(res => {
console.log(res)
setPosts(res.data)
})
.catch(err => {
console.log(err)
})
}, [])
return …
Run Code Online (Sandbox Code Playgroud) 我是一名 C# 开发人员,正在尝试进入前端(React using typescript)。我正在努力让我的笑话测试进行起来。另外,如何自动更新快照?
我的组件;
import { forwardRef } from 'react';
import styled from 'styled-components';
interface Props {
className?: string;
placeholder?: string;
onFocus?: Function;
name?: string;
onChange?: (event: any | boolean) => void;
value?: string;
id?: string;
disabled?: boolean;
type?: string;
onBlur?: (event: any) => void;
}
const TextBox = styled.input`
padding: 0;
line-height: 1;
border: none;
background: transparent none;
appearance: none;
-webkit-tap-highlight-color: transparent;
display: block;
width: 100%;
height: 4.4rem;
padding: 0.5rem 1.5rem;
font-weight: normal;
border: 0.1rem solid ; …
Run Code Online (Sandbox Code Playgroud) 对于从db读取的记录,然后构建一个字符串,我具有以下orderby。以下代码可以正常工作,但是我知道可以改进任何建议,对此表示高度赞赏。
result.Sites.ForEach(x =>
{
result.SiteDetails +=
string.Concat(ICMSRepository.Instance.GetSiteInformationById(x.SiteInformationId).SiteCode,
",");
});
//Sort(Orderby) sites by string value NOT by numerical order
result.SiteDetails = result.SiteDetails.Trim(',');
List<string> siteCodes = result.SiteDetails.Split(',').ToList();
var siteCodesOrder = siteCodes.OrderBy(x => x).ToArray();
string siteCodesSorted = string.Join(", ", siteCodesOrder);
result.SiteDetails = siteCodesSorted;
Run Code Online (Sandbox Code Playgroud)