ts中引入js文件以及使用全局js方法报错问题

ts中引入js报错

一、 无法找到模块“@/xxx/xxx”的声明文件。“xxx.js”隐式拥有 “any” 类型。 [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Txigu319-1631930149705)(C:\Users\oyzq\AppData\Roaming\Typora\typora-user-images\1631929576599.png)]

解决办法:

使用 require引用

const {
    
     encryptionJump,decryptJump } = require("@/utils/rsa")

二、ts中使用全局js方法报错

在这里插入图片描述

解决办法

  1. 申明多个挂载到全局
declare const window: Window & {
    
     SG_sm2Encrypt: any,SG_sm2Decrypt: any,format:any };

使用时用window

 window.SG_sm2Encrypt(data, pubkeyHex);
  1. 单个申明
declare var SG_sm2Encrypt:(data:any,hex:any)=>any

使用时正常使用即可

SG_sm2Encrypt(data, pubkeyHex)

SG_sm2Encrypt(data, pubkeyHex)

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_42068550/article/details/120361671