【问题标题】:Data version error in SPFX React -Basic WebpartSPFX React -Basic Webpart 中的数据版本错误
【发布时间】:2021-01-22 08:55:33
【问题描述】:

我刚刚创建了一个带有 react 的基本 spfx webpart,但出现以下错误:

{ "资源": "/c:/Node_Dev/CRUD_React/src/webparts/crudReact001/CrudReact001WebPart.ts", “所有者”:“打字稿”, “代码”:“2611”, “严重性”:8, "message": "'dataVersion' 被定义为 'BaseClientSideWebPart' 类中的一个属性,但在 'CrudReact001WebPart' 中作为访问器被覆盖。", “来源”:“ts”, “开始线号”:35, “开始列”:17, "endLineNumber": 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
                })
              ]
            }
          ]
        }
      ]
    };
  }
}

【问题讨论】:

    标签: reactjs sharepoint web-parts spfx


    【解决方案1】:

    下面链接的文章提供了有关该问题的更多详细信息:

    https://dreamsof.dev/2020-09-21-typescript-upgrade-breaking-dataversion-get-override-spfx11/

    建议的解决方案是:

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

    【讨论】:

      【解决方案2】:

      你可以删除'datavaersion'方法,它与SPFx v1.10兼容,但安装V1.11时会出错。

      【讨论】:

      • 是否有任何其他信息说明为什么会发生此错误以及为什么删除该方法是安全的?这会从 yeoman 生成器中删除吗?
      猜你喜欢
      • 2021-04-20
      • 2022-11-23
      • 2020-12-13
      • 2021-07-18
      • 2019-03-26
      • 2022-01-11
      • 2020-03-17
      • 2017-06-14
      • 2020-12-10
      相关资源
      最近更新 更多