【发布时间】:2020-03-05 12:48:28
【问题描述】:
我正在为一个项目使用 Stencil.js(打字稿)。我需要实现这个selectbox。
这是我的代码:
import { Component, h, JSX, Prop, Element } from '@stencil/core';
import Selectr from 'mobius1-selectr';
@Component({
tag: 'bldc-selectbox',
styleUrl: 'bldc-selectbox.scss',
shadow: true
})
export class BldcSelectbox {
@Element() el: HTMLElement;
componentDidLoad() {
//init selectbox
new Selectr(this.el.shadowRoot.querySelector('#mySelect') as HTMLOptionElement, {// document.getElementById('mySelect'), {
searchable: true,
width: 300
});
}
render(): JSX.Element {
return <div>
<section>
<select id="mySelect">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</section>
</div>
}
}
请检查结果的图像。它确实出现了,但是当我单击它时它什么也没做。
更新 1: 我刚刚发现它确实可以在没有 CSS 样式的情况下工作。
【问题讨论】:
标签: javascript typescript import stenciljs