简体   繁体   English

如何从React Typescript组件调用jQuery函数?

[英]How to call jQuery function from React typescript component?

I want to call AdminLTE javascript object from my .tsx file but got an error like this: 我想从我的.tsx文件中调用AdminLTE javascript对象,但是出现了如下错误:

[ts] Property 'AdminLTE' does not exist on type 'JQueryStatic'. [ts]类型“ JQueryStatic”上不存在属性“ AdminLTE”。

In AdminLTE.js file, the declaration looks like: 在AdminLTE.js文件中,声明如下所示:

$.AdminLTE = {};

In my typescript file, I called using: 在我的打字稿文件中,我使用了:

componentDidMount() {
  $.AdminLTE.layout.fix(); // Got error
}

Is there anybody know how to fix it? 有谁知道如何解决?

You have a couple of options: 您有两种选择:

Option 1: Install the typings for the AdminLTE plugin if they exist. 选项1:安装AdminLTE插件的类型(如果存在)。 (I can't find the typings for this in npm, you may have to contact the plugin owner if typings exist for this) (我在npm中找不到此类型,如果存在此类型,您可能必须联系插件所有者)

Option 2: Declare AdminLTE as any . 选项2:将 AdminLTE声明为any You can access AdminLTE without any type restrictions: 您可以不受任何类型限制地访问AdminLTE

declare var $: JQueryStatic & {
    AdminLTE: any
}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM