SPFX React -Basic Webpart中的数据版本错误

问题描述

我刚刚创建了一个带有反应但出现以下错误的基本spfx Webpart:

{ “ resource”:“ /c:/Node_Dev/CRUD_React/src/webparts/crudReact001/CrudReact001WebPart.ts”, “ owner”:“打字稿”, “ code”:“ 2611”, “严重程度”:8 “ message”:“'dataVersion'被定义为类'BaseClientSideWebPart'中的一个属性,但在此'CrudReact001WebPart'中被覆盖为访问器。 “ source”:“ ts”, “ startLineNumber”:35, “ startColumn”:17 “ endLineNumber”:35, “ endColumn”: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/

建议的解决方案是:

  1. 将Workspace版本用于TypeScript(3.3.4000),而不是VS Code的较新版本
  2. // @ts-ignore装饰方法

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...