jquery - Jquery 不监听 Typescript 中的事件
问题描述
我正在尝试捕获打开和关闭引导手风琴的事件,但是使用打字稿,事件不会“收听”,但是使用 JS 可以正常工作!
错误:
module "c:/Users/THIAGOSAAD/Documents/DEVELOPMENT/NEORIS/ALIANSCE/appcomercial/build/typescript/types/jquery"
This module can only be referenced with ECMAScript imports/exports by turning on the 'allowSyntheticDefaultImports' flag and referencing its default export.ts(2497)
查询类型
export = jquery;
declare function jquery(w: any): any;
班级
import * as $ from '../types/jquery';
export class BootstrapAccordionController {
private readonly _iconStateContainer: HTMLElement;
public constructor(private readonly _accordionID: string, public readonly iconStateContainerID: string) {
this._iconStateContainer = document.getElementById(iconStateContainerID);
}
public init(): void {
try {
this.changeIconState();
} catch (error) {
console.error(error);
}
}
private changeIconState(): void {
$(`#${this._accordionID}`).on('shown.bs.collapse', () => this.createIconState('shown.bs.collapse'));
$(`#${this._accordionID}`).on('hidden.bs.collapse', () => this.createIconState('hidden.bs.collapse'));
}
private createIconState(_stateType: string): void {
switch(_stateType) {
case 'shown.bs.collapse':
this._iconStateContainer.innerHTML = `<h3 data-name="accordion-collapse-icon"><i class="fas fa-angle-up align-middle"></i></h3>`
break;
case 'hidden.bs.collapse':
this._iconStateContainer.innerHTML = `<h3 data-name="accordion-collapse-icon"><i class="fas fa-angle-down align-middle"></i></h3>`
break;
}
}
}
解决方案
此模块只能通过打开“allowSyntheticDefaultImports”标志并引用其默认 export.ts(2497) 来引用 ECMAScript 导入/导出
设置esModuleInterop
为true
。这反过来也将打开合成默认导入。
推荐阅读
- position - 如何在 Yandex 地图中将所选点定位在地图顶部
- security - 在数据库泄露的情况下保护多个用户身份的匿名性
- java - 运行 java servlet 时获取 java.lang.ClassNotFoundException
- chart.js - chart.js 时间序列多轴案例
- python - 为什么在安装 pyxll 时出现此错误?
- python - 为“cudf”做“diff”的最有效方法是什么
- python - node进程和python子进程之间的双向通信
- java - 我在哪里放置我的资源文件以使其在 Spring 中使用类路径可读?
- java - 本地开发不能禁用 Spring 配置服务器
- apache - htaccess 错误页面文件不适用于重写条件