我想在Aurelia SPA的打字稿页面内使用一个jquery插件。这个插件叫做morelines
到目前为止,这是我目前的解决方案:
我的打字稿文件:post.ts
import './jquery.morelines'
export class Post {
attached() {
$('.card__description--details').moreLines({
linecount: 6,
baseclass: 'b-description',
basejsclass: 'js-description',
classspecific: '_readmore',
buttontxtmore: "",
buttontxtless: "",
animationspeed: 400
});
}
}
插件jquery.morelines.js
(function ( $ ) {
$.fn.moreLines = function (options) {
...
}
}(jQuery));
我的[[tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"sourceMap": true,
"target": "es5",
"module": "amd",
"declaration": false,
"noImplicitAny": false,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowJs": true,
"moduleResolution": "node",
"lib": ["es2017", "dom"],
"baseUrl": "src"
},
"include": [
"./src/**/*.ts",
"./test/**/*.ts"
],
"atom": {
"rewriteTsconfig": false
}
}
它在运行时有效,但在捆绑(au build
)时出现错误如何摆脱这些错误?如何在我的打字稿文件中正确引用此javascript jquery插件?
aurelia.json
"dependencies": [
...
...
{
"name": "jquery.morelines",
"path": "../javascript",
"main": "jquery.morelines",
"deps": [
"jquery"
]
}
]
无需在我的打字稿页面中添加任何import
。posts.ts
...
(<any>$('.card__description--details')).moreLines({
linecount: 6,
baseclass: 'b-description',
basejsclass: 'js-description',
classspecific: '_readmore',
buttontxtmore: "",
buttontxtless: "",
animationspeed: 400
});