将bootstrap.js导入lit-element组件

时间:2019-10-08 17:47:48

标签: twitter-bootstrap polymer lit-element

我有一个亮元素组件,可以正确呈现引导程序下拉菜单,但是单击下拉菜单时,菜单不会出现。我意识到这是一个JavaScript问题,但是我不清楚如何解决该问题。我在我的index.html文件中导入了引导捆绑包js。我正在链接到组件中的引导CSS。

我的index.html文件中有

<script src="node_modules/jquery/dist/jquery.min.js"></script>
<script defer src="node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"></script>

在我的照明元素组件的渲染中

 <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> 

同样,由于所有内容均正确呈现,因此可以识别css。该问题与下拉菜单的操作有关。

已更新,以包含每个注释请求的组件代码:

import { html } from 'lit-element';
import { PageViewElement } from './page-view-element.js';
import { connect } from 'pwa-helpers/connect-mixin.js';

// This element is connected to the Redux store.
import { store } from '../store.js';

// These are the actions needed by this element.
import { increment, decrement } from '../actions/counter.js';
import '@polymer/paper-input/paper-input.js'
import '@polymer/paper-dropdown-menu/paper-dropdown-menu.js';
import '@polymer/paper-item/paper-item.js';
import '@polymer/paper-listbox/paper-listbox.js';


// These are the shared styles needed by this element.
import { SharedStyles } from './shared-styles.js';
class MyComponent extends connect(store)(PageViewElement) {
  static get properties() {
    return {
    };
  }

  constructor() {
    super();
  }

  static get styles() {
    return [
      SharedStyles
    ];
  }

  firstUpdated(){}

  render() {
    return html`
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
      <section>
        <form onsubmit="return false">
          <div class="form-row">
            <div class="form-group col-sm-4">
              <div class="input-group mb-3">
                <input id=“my-input“ type="text" class="form-control">
              </div>
          </div>
          <div class="form-row">
            <div class="dropdown">
              <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                 Dropdown button
              </button>
              <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                  <a class="dropdown-item" href="#">Action</a>
                  <a class="dropdown-item" href="#">Another action</a>
                  <a class="dropdown-item" href="#">Something else here</a>
              </div>
            </div>
          </div>
        </form>
      </section>
      <section>
    </section>
    `;
  }
}

window.customElements.define('my-component', MyComponent);

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

可悲的是,我不能只发表评论。而且我的回答实际上还不够大,不能以邮寄作为回答,而不能发表评论。

但是您是否尝试过在主html上添加像usall这样的样式表,并只是将相应的bootstrap-class添加到lit-element中的元素。 (我只是从您的问题中复制链接,所以我不保证这些工作)

index.html:

<script src="node_modules/jquery/dist/jquery.min.js"></script>
<script defer src="node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"></script>

<your-element></your-element>

your-element.js:

render() {
    return html`
      <p class="badge badge-secondary"></p>

`

希望这对您有帮助...