【问题标题】:Property 'getTrimmedCanvas' does not exist on type '{}'.ts(2339), Signature Pad类型“{}”.ts(2339) 上不存在属性“getTrimmedCanvas”,签名板
【发布时间】:2021-03-08 06:59:42
【问题描述】:

我正在尝试在我的应用中实现一个功能,以便用户可以签署 PDF。我在 CodeSandbox 上找到了 Signature Pad 的示例,我尝试将其插入到我的项目中,但出现了 2 个错误:

Property 'getTrimmedCanvas' does not exist on type '{}'.ts(2339)

Property 'clear' does not exist on type '{}'.ts(2339)

Codesource Signature Pad example

有错误的代码部分

import Popup from "reactjs-popup";
import SignaturePad from "react-signature-canvas";
import { useState, useRef } from "react";
import React from "react";

function Button() {
  const sigCanvas = useRef({});
  const [imageURL, setImageURL] = useState(null);
  const clear = () => sigCanvas.current.clear();
  const save = () =>setImageURL(sigCanvas.current.getTrimmedCanvas().toDataURL("image/png"));

  return (

//for more Code use the Link: Codesource Signature Pad example

  );
}

export default Button;

我已经安装了这两个库:

npm install --save reactjs-popup
npm install --save react-signature-canvas

知道如何解决它们吗? 非常感谢

【问题讨论】:

    标签: reactjs signaturepad


    【解决方案1】:

    非常简单,您使用的是导致问题的 .tsx 文件。只需将文件类型从 tsx 更改为 .js 或 .jsx 即可:)

    【讨论】:

      【解决方案2】:

      我解决了这个问题,在 useRef 中添加一个类型:

      const sigCanvas = useRef<any>();
      

      【讨论】:

        猜你喜欢
        • 2021-01-10
        • 2020-08-29
        • 2019-08-11
        • 2021-08-02
        • 2020-06-02
        • 2022-07-09
        • 2022-10-04
        • 2023-02-07
        • 2020-08-23
        相关资源
        最近更新 更多