【发布时间】:2019-09-14 20:54:33
【问题描述】:
我找不到一个很好的例子来说明如何将Bootstrap Tour 与 Aurelia 一起使用。我用 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
我做错了什么?
【问题讨论】:
-
您好,请说明:typescript 还是 ecma6?你在用 webpack 吗?
-
我看了看,问题似乎是 Tour 的导出方式。请再试一次: import Tour from 'bootstrap-tour' without the括号。
-
我认为问题在于你试图注入它,而不是直接使用它。
-
要么使用 DI 注册该类(并使用 this.tour 代替 new this.tour),要么在构造函数中使用 new Tour(并使用 this.tour 代替 new this.tour)跨度>