与 Aurelia 一起使用 bootstrap-tour

Using bootstrap-tour with Aurelia

我无法找到如何将 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';

在我的 class 定义中:

@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

我做错了什么?

Cristián Ormazábal、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 可能是一个废弃的 repo。它目前与 Bootstrap 3.4.1(最新的 v3 版本)不兼容,因此对我没用。如果有人仍想使用它,这里有一些解决方法和一个替代的分叉回购:

https://github.com/sorich87/bootstrap-tour/issues/723