SPFX React -Basic Webpart 中的数据版本错误
Data version error in SPFX React -Basic Webpart
我刚刚创建了一个带有反应的基本 spfx webpart,但出现以下错误:
{
"资源": "/c:/Node_Dev/CRUD_React/src/webparts/crudReact001/CrudReact001WebPart.ts",
“所有者”:“打字稿”,
“代码”:“2611”,
“严重性”:8,
"message": "'dataVersion' 在 class 'BaseClientSideWebPart' 中定义为 属性,但在 'CrudReact001WebPart' 中作为访问器被覆盖。",
“来源”:“TS”,
“开始行号”:35,
“开始列”:17,
“结束行号”:35,
“结束列”:28
}
我的代码:
import * as React from 'react';
import * as ReactDom from 'react-dom';
import { Version } from '@microsoft/sp-core-library';
import {
IPropertyPaneConfiguration,
PropertyPaneTextField
} from '@microsoft/sp-property-pane';
import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';
import * as strings from 'CrudReact001WebPartStrings';
import CrudReact001 from './components/CrudReact001';
import { ICrudReact001Props } from './components/ICrudReact001Props';
export interface ICrudReact001WebPartProps {
description: string;
}
export default class CrudReact001WebPart extends BaseClientSideWebPart<ICrudReact001WebPartProps> {
public render(): void {
const element: React.ReactElement<ICrudReact001Props> = React.createElement(
CrudReact001,
{
description: this.properties.description
}
);
ReactDom.render(element, this.domElement);
}
protected onDispose(): void {
ReactDom.unmountComponentAtNode(this.domElement);
}
protected get dataVersion(): Version {
return Version.parse('1.0');
}
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
return {
pages: [
{
header: {
description: strings.PropertyPaneDescription
},
groups: [
{
groupName: strings.BasicGroupName,
groupFields: [
PropertyPaneTextField('description', {
label: strings.DescriptionFieldLabel
})
]
}
]
}
]
};
}
}
您可以删除'datavaersion'方法,它与SPFx v1.10兼容,但在安装V1.11时会出错。
下面链接的文章提供了有关该问题的更多详细信息:
https://dreamsof.dev/2020-09-21-typescript-upgrade-breaking-dataversion-get-override-spfx11/
建议的解决方案是:
- 使用 TypeScript 的 Workspace 版本 (3.3.4000) 而不是 VS Code 的较新版本
- 装饰方法
// @ts-ignore
我刚刚创建了一个带有反应的基本 spfx webpart,但出现以下错误:
{ "资源": "/c:/Node_Dev/CRUD_React/src/webparts/crudReact001/CrudReact001WebPart.ts", “所有者”:“打字稿”, “代码”:“2611”, “严重性”:8, "message": "'dataVersion' 在 class 'BaseClientSideWebPart' 中定义为 属性,但在 'CrudReact001WebPart' 中作为访问器被覆盖。", “来源”:“TS”, “开始行号”:35, “开始列”:17, “结束行号”:35, “结束列”:28 }
我的代码:
import * as React from 'react';
import * as ReactDom from 'react-dom';
import { Version } from '@microsoft/sp-core-library';
import {
IPropertyPaneConfiguration,
PropertyPaneTextField
} from '@microsoft/sp-property-pane';
import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';
import * as strings from 'CrudReact001WebPartStrings';
import CrudReact001 from './components/CrudReact001';
import { ICrudReact001Props } from './components/ICrudReact001Props';
export interface ICrudReact001WebPartProps {
description: string;
}
export default class CrudReact001WebPart extends BaseClientSideWebPart<ICrudReact001WebPartProps> {
public render(): void {
const element: React.ReactElement<ICrudReact001Props> = React.createElement(
CrudReact001,
{
description: this.properties.description
}
);
ReactDom.render(element, this.domElement);
}
protected onDispose(): void {
ReactDom.unmountComponentAtNode(this.domElement);
}
protected get dataVersion(): Version {
return Version.parse('1.0');
}
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
return {
pages: [
{
header: {
description: strings.PropertyPaneDescription
},
groups: [
{
groupName: strings.BasicGroupName,
groupFields: [
PropertyPaneTextField('description', {
label: strings.DescriptionFieldLabel
})
]
}
]
}
]
};
}
}
您可以删除'datavaersion'方法,它与SPFx v1.10兼容,但在安装V1.11时会出错。
下面链接的文章提供了有关该问题的更多详细信息:
https://dreamsof.dev/2020-09-21-typescript-upgrade-breaking-dataversion-get-override-spfx11/
建议的解决方案是:
- 使用 TypeScript 的 Workspace 版本 (3.3.4000) 而不是 VS Code 的较新版本
- 装饰方法
// @ts-ignore