[英]Ionic 3 with Jquery Plugin
Hi there people I hope you can help me with this one. 嗨,大家好,我希望你能帮我这个忙。 I've been trying from two days to use Jquery Plugin with Ionic 3 but to no avail, I'm using it for my project and if I could, I would avoid it but I don't have time or enough knowledge to make custom thing. 我已经尝试了两天,将Jquery Plugin与Ionic 3一起使用,但无济于事,我在项目中使用了它,如果可以的话,我会避免使用它,但是我没有时间或足够的知识来进行自定义事情。
I'm trying to create a roulette and I'm using roulette.js plugin, but I keep receiving error from webpack that WEBPACK_IMPORTED_MODULE_2_jquery (...).roulette is not a function. 我正在尝试创建轮盘,并且正在使用roulette.js插件,但我不断收到来自webpack的错误,即WEBPACK_IMPORTED_MODULE_2_jquery (...)。轮盘不是一个函数。
Now I tried couple of things I turned js file from library into .ts and then I cast it to any as shown below. 现在,我尝试了几种方法,将js文件从库转换为.ts,然后将其转换为如下所示的任何文件。 I also added it to index.d.ts. 我也将其添加到index.d.ts。 I created Jquery interface but no luck. 我创建了Jquery接口,但是没有运气。 Is there something I'm missing? 有什么我想念的吗? I installed jquery and @types/jquery, Jquery works like charm, only plugin is not working. 我安装了jquery和@ types / jquery,Jquery的工作原理类似于魅力,仅插件无法正常工作。
component.ts component.ts
ionViewDidLoad() {
((<any>$('div.roulette')) as any).roulette();
}
roulette.ts 轮盘赌
var pluginName = 'roulette';
$.fn[pluginName] = function(method, options) {
return this.each(function() {
var self = $(this);
var roulette = self.data('plugin_' + pluginName);
if (roulette) {
if (roulette[method]) {
roulette[method](options);
} else {
console &&
console.error(
'Method ' + method + ' does not exist on jQuery.roulette'
);
}
} else {
roulette = new (Roulette(method) as any)();
roulette.init(self, method);
$(this).data('plugin_' + pluginName, roulette);
}
});
};
export { Roulette };
index.d.ts 索引
interface Jquery {
roullete: (options:any) => void
}
So after long searching about a week, i found out that you have to add you plugin to jquery typings 因此,经过漫长的搜索大约一个星期,我发现您必须将插件添加到jquery类型中
interface JQueryStatic {
pluginName: (options:any) => void
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.