在本文中,我们将为您详细介绍类型错误:无法读取Reactjs的相关知识,并且为您解答关于无法读取actors.json的疑问,此外,我们还会提供一些关于Angular-错误类型错误:无法读取未定义的属
在本文中,我们将为您详细介绍类型错误:无法读取 React js的相关知识,并且为您解答关于无法读取actors.json的疑问,此外,我们还会提供一些关于Angular - 错误类型错误:无法读取未定义的属性“名称”、React/MaterialUI - 类型错误:无法读取未定义的属性“地图”、× 类型错误:无法读取 null 的属性“map”、“类型错误:无法读取未定义的属性‘过滤器’”以及类似的其他数组函数,如使用 ReactJS 和 redux 的 map的有用信息。
本文目录一览:- 类型错误:无法读取 React js(无法读取actors.json)
- Angular - 错误类型错误:无法读取未定义的属性“名称”
- React/MaterialUI - 类型错误:无法读取未定义的属性“地图”
- × 类型错误:无法读取 null 的属性“map”
- “类型错误:无法读取未定义的属性‘过滤器’”以及类似的其他数组函数,如使用 ReactJS 和 redux 的 map
类型错误:无法读取 React js(无法读取actors.json)
如何解决类型错误:无法读取 React js?
提交表单时出现错误,错误如下..
TypeError: 无法读取未定义的属性 ''payload''
如果你想知道更多信息告诉我
reducer/index.js
export default (posts =[],action) => {
switch(action.type){
case ''FETCH_ALL'':
return action.payload;
case ''CREATE'':
return [...posts. action.payload];
default:
return posts;
}
}
操作/posts.js
import * as api from ''../api'';
//动作创建者
export const getPosts = () => async (dispatch) => {
try {
const { data } = await api.fetchPosts();
dispatch({ type: ''FETCH_ALL'',payload: data })
} catch (error) {
console.log(error.message)
}
}
export const createPost = (post) => async (dispatch) =>{
try{
const {data} = await api.createPost(post);
dispatch({type: ''CREATE'',payload:data})
}catch(error){
console.log(error);
}
}
API/index.js
import axios from ''axios'';
const url = "http://localhost:7000/posts";
export const fetchPosts = () => axios.get(url);
export const createPost = (newPost) => axios.post(url,newPost);
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
Angular - 错误类型错误:无法读取未定义的属性“名称”
如何解决Angular - 错误类型错误:无法读取未定义的属性“名称”?
在我的 Angular-12 项目中,我使用以下代码注册用户并使用 Laravel-8 api 将图像插入到目录和数据库中:
界面:
export interface ICompanySetup {
companyName: string;
registrationNumber: string;
dateEstablished: Date;
company_logo: any;
}
服务:
createCompanySignup(data: any): Observable<ICompanySetup[]> {
return this.http.post<ICompanySetup[]>(this.api.baseURL + ''signup'',data,this.httpOption);
}
组件:
import {
ApiService
} from ''src/app/services/api.service'';
export class SignupComponent implements OnInit {
isLinear = true;
isLoading = false;
companySetupForm!: FormGroup;
companyForm!: FormGroup;
idForm!: FormGroup;
imageSrclogo!: string | ArrayBuffer;
files: any;
constructor(
private fb: FormBuilder,private api: ApiService,private route: Router,) {}
onFileChange(event: any) {
const reader = new FileReader();
if (event.target.files && event.target.files.length) {
const [file] = event.target.files;
reader.readAsDataURL(file);
reader.onload = () => {
this.imageSrclogo = reader.result as string;
this.companyInfoForm.get(''company_logo'') ? .setValue(file);
};
}
}
ngOnInit() {
this.companyForm = this.fb.group({
companyName: ['''',[Validators.required,Validators.minLength(3),Validators.maxLength(100)]],dateEstablished: ['''',[Validators.required]],company_logo: ['''',[
RxwebValidators.extension({
extensions: ["jpg","jpeg","bmp","png","gif","svg"]
})
]],},{
updateOn: "blur"
});
this.idForm = this.fb.group({
registrationNumber: ['''',});
}
get fc() {
return this.companyForm.controls;
};
get fi() {
return this.idForm.controls;
};
onSubmit() {
this.isSubmitted = true;
const formCompanyData = this.companyForm.getRawValue();
const formIdData = this.idForm.getRawValue();
const formData = new FormData();
var datestr = (new Date(formCompanyData.dateEstablished)).toUTCString();
formData.append(''companyName'',formCompanyData.companyName);
formData.append("company_logo",this.files,this.files.name);
formData.append(''registrationNumber'',formCompanyData.registrationNumber);
formData.append("dateEstablished",datestr);
this.spinnerService.show();
const header = {
''Content-Type'': ''application/json''
};
this.isLoading = true;
this.companyService.createCompanySignup(formData).subscribe((res: any) => {
this.router.navigate([''admin/category'']).then(() => this.showToasterSuccess(res.message));
},error => this.router.navigate([''admin/category'']).then(() => this.showToasterError(error[0].message))
);;
}
}
HTML:
<mat-horizontal-stepper [linear]="isLinear" #stepper labelPosition="bottom">
<mat-step [stepControl]="companyForm">
<form [formGroup]="companyForm">
<ng-template matStepLabel matStepperIcon="phone">Company Info</ng-template>
<div>
<div>
<divhttps://www.jb51.cc/tag/Box/" target="_blank">Box-profile">
<div>
<img[src]="imageSrclogo || ''assets/img/no-image.png''" alt="No Company logo">
</div>
<h3>Company logo</h3>
<div>
<label for="file"></label>
<input formControlName="company_logo" id="file" type="file"(change)="onFileChange($event)">
</div>
</div>
</div>
</div>
<div>
<div>
<label for="dateEstablished">Date Registered:<span>*</span></label>
<mat-form-field fxFlex="100%" fxFlex.gt-sm>
<input matInput [matDatepicker]="dateEstablished" placeholder="Choose a date" [max]="tomorrow" formControlName="dateEstablished" readonly required>
<mat-datepicker-toggle matSuffix [for]="dateEstablished"></mat-datepicker-toggle>
<mat-datepicker #dateEstablished></mat-datepicker>
</mat-form-field>
</div>
<div *ngIf="fc.dateEstablished.touched && fc.dateEstablished.invalid">
<div *ngIf="fc.dateEstablished.hasError(''required'')">
<div>
Date Registered is required!
</div>
</div>
</div>
</div>
<div>
<div>
<label for="name">Company Name:<span>*</span></label>}
<input type="text" formControlName="companyName" placeholder="Company Name"required/>
</div>
<div *ngIf="fc.companyName.touched && fc.companyName.invalid">
<div *ngIf="fc.companyName.hasError(''required'')">
<div>
Company Name is required!
</div>
</div>
<div *ngIf="fc.companyName.hasError(''minlength'')">
<div>
Company Name cannot be less than 3 characters!
</div>
</div>
<div *ngIf="fc.companyName.hasError(''maxlength'')">
<div>
Company Name cannot be more than 100 characters!
</div>
</div>
</div>
</div>
<div>
<button mat-raised-button color="primary" matStepperNext [disabled]="companyForm.status != ''VALID''">Next</button>
</div>
</form>
</mat-step>
<mat-step [stepControl]="idForm">
<form [formGroup]="idForm">
<ng-template matStepLabel>Company ID</ng-template>
<div>
<div>
<label for="registration_number">Registration Number:<span>*</span></label>
<input type="text" formControlName="registrationNumber" placeholder="Registration Number"required/>
</div>
<div *ngIf="fi.registrationNumber.touched && fi.registrationNumber.invalid">
<div *ngIf="fi.registrationNumber.hasError(''required'')">
<div>
Company Reg. No. is required!
</div>
</div>
<div *ngIf="fi.registrationNumber.hasError(''maxlength'')">
<div>
Company Reg. No. cannot be more than 100 characters!
</div>
</div>
</div>
</div>
<div>
<button mat-raised-button color="black" matStepperPrevIoUs>Back</button>
<button mat-raised-button color="success" [disabled]="isLoading" type="submit" (click)="onSubmit()">
<span *ngIf="isLoading"></span>
Submit
</button>
<button mat-raised-button color="warn" (click)="stepper.reset()">Reset</button>
</div>
</mat-step>
</mat-horizontal-stepper>