我还没有找到一个很好的例子来说明如何在Aurelia中使用Bootstrap Tour。我用yarn (yarn add bootstrap-tour)安装了它,并在main.js中添加了依赖项,如下所示:
import 'bootstrap/dist/css/bootstrap.min.css';
import 'bootstrap-tour/build/css/bootstrap-tour.min.css';
import 'bootstrap/dist/js/bootstrap.min.js';
import 'bootstrap-tour/build/js/bootstrap-tour.min.js';现在我想在我的一个视图模型中使用它。下面是我尝试过的:
import { Tour } from 'bootstrap-tour';在我的类定义中:
@inject(Store, EventAggregator, I18N, Router, Tour)
export default class {
constructor(store, events, i18n, router, tour) {
this.store = store;
this.events = events;
this.i18n = i18n;
this.router = router;
this.tour = tour;
}
// ... other methods and code
startTour() {
const tourNewReports = new this.tour({
steps: [
{
element: '#tour-btn-menu',
title: 'New reports!',
content: 'Check out new reports!',
},
{
element: '.tour-label-product',
title: 'Product report',
content: 'Click on a specific product to see more reports.',
},
],
});
tourNewReports.init();
tourNewReports.start();
}
}然而,这甚至不能编译,我得到了以下错误:
Error: Error invoking _class3. Check the inner error for details.
------------------------------------------------
Inner Error:
Message: key/value cannot be null or undefined. Are you trying to inject/register something that doesn't exist with DI?
Inner Error Stack:
Error: key/value cannot be null or undefined. Are you trying to inject/register something that doesn't exist with DI?我还尝试跳过注入,只使用const tourNewReports = new Tour({,但是我得到了这个错误:
bootstrap_tour__WEBPACK_IMPORTED_MODULE_6__.Tour is not a constructor
at _class3.startTour我做错了什么?
发布于 2019-09-14 20:54:34
克里斯蒂安·奥尔马扎巴尔、avrahamcool和Rabah G的评论对我解决这个问题很有帮助。最简单的解决方案是:
import Tour from 'bootstrap-tour';然后,直接使用,如下所示:
startTour() {
const tourNewReports = new Tour({
steps: [
{
element: '#tour-btn-menu',
title: 'New reports!',
content: 'Check out new reports!',
},
{
element: '.tour-label-product',
title: 'Product report',
content: 'Click on a specific product to see more reports.',
},
],
});
tourNewReports.init();
tourNewReports.start();
}然而,最终看来,bootstrap-tour可能是一种废弃的回购。它目前与Bootstrap 3.4.1 (最新的v3版本)不兼容,因此对我来说毫无用处。如果有人仍然想使用它,这里有几个变通方法和一个替代的forked repo:
https://stackoverflow.com/questions/57890940
复制相似问题