简体   繁体   English

错误 TS2339:“文件上传”类型上不存在属性“_input”

[英]error TS2339: Property '_input' does not exist on type 'FileUpload

I am attempting to run the below code but experiencing these errors我正在尝试运行以下代码但遇到这些错误

Property '_input' does not exist on type 'FileUpload'. Property '_input' does not exist on type 'FileUpload'. Property 'context' does not exist on type 'Readonly<{ children?: ReactNode; }> & Readonly<IFileUploadProps>
export default class FileUpload extends React.Component<IFileUploadProps, {}> {
    public render(): React.ReactElement<IFileUploadProps> {
        return (
            <div className={styles.fileUpload}>
                <div className={styles.container}>
                    <div className={styles.row}>
                        <div className={styles.column}>
                            <span className={styles.title}>SharePoint!</span>
                            <p className={styles.subTitle}> Web Parts.</p>
                            <p className={styles.description}>{escape(this.props.description)}</p>
                            <a href="https://aka.ms/spfx" className={styles.button}>
                                <span className={styles.label}>Learn more</span>
                            </a>
                            <input
                                type="file"
                                ref={(elm) => {
                                    this._input = elm;
                                }}
                            />
                            <p>
                                <button onClick={() => this.uploadFileFromControl()}>Upload</button>
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        );
    }
    private uploadFileFromControl() {
        //Get the file from File DOM
        var files = this._input.files;
        var file = files[0];
        //Upload a file to the SharePoint Library
        sp.web
            .getFolderByServerRelativeUrl(this.props.context.pageContext.web.serverRelativeUrl + '/OrderLibrary')
            .files.add(file.name, file, true)
            .then((data) => {
                alert('File uploaded sucessfully');
            })
            .catch((error) => {
                alert('Error is uploading');
            });
    }
}

Sample demo to declare a ref:声明 ref 的示例演示:

//define a variable in component
protected ppl;

<PeoplePicker
              context={this.props.context}
              titleText="People Picker"
              personSelectionLimit={3}
              groupName={''}
              showtooltip={false}
              isRequired={false}
              disabled={false}
              selectedItems={this._getPeoplePickerItems}
              defaultSelectedUsers={this.state.PeoplePickerDefaultItems}
              showHiddenInUI={false}
              principalTypes={[PrincipalType.User]}
              resolveDelay={1000}
              ref={c => (this.ppl = c)} 
            />
 <button onClick={() => {this.ppl.

To use webpart context, you need send it from webpart class.要使用 webpart 上下文,您需要从 webpart class 发送它。

const element: React.ReactElement<IPnpReactProps > = React.createElement(
      PnpReact,
      {
        description: this.properties.description,
        context:this.context
      }
    );

Component property.组件属性。

import { WebPartContext } from '@microsoft/sp-webpart-base';
export interface IPnpReactProps {
  description: string;
  context: WebPartContext;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 输入字段上的“TS2339:属性...在类型...上不存在” - “TS2339: Property … does not exist on type …”, on input field TS2339:属性在类型上不存在 - TS2339: Property does not exist on type 错误TS2339:类型“功能”上不存在属性“名称” - Error TS2339: Property 'name' does not exist on type 'Function' 错误 TS2339:类型“{}”上不存在属性“contenido” - error TS2339: Property 'contenido' does not exist on type '{}' 错误TS2339:类型“字符串”上不存在属性“默认”。** - Error TS2339: Property 'Default' does not exist on type 'string'.** 错误TS2339:类型“ UserCredential”上不存在属性“ sendemailverification” - error TS2339: Property 'sendemailverification' does not exist on type 'UserCredential' 错误 TS2339:“RegisterComponent”类型上不存在属性“隐藏” - error TS2339: Property 'hide' does not exist on type 'RegisterComponent' 错误 TS2339:“混合”类型上不存在属性“坐标” - error TS2339: Property 'coord' does not exist on type 'Mixed' 错误 TS2339:“日期”类型上不存在属性“addHours” - error TS2339: Property 'addHours' does not exist on type 'Date' 错误 TS2339:“AngularFireAuth”类型上不存在属性“auth” - error TS2339: Property 'auth' does not exist on type 'AngularFireAuth'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM