我有一个基于 Swiperjs 第三方库的轮播。问题是,当我使用 scope: true 时,我没有问题并且工作正常,但是,当我尝试使用 shadow: true 配置组件时,它被破坏并且没有任何作用。我正在使用以下库:
...
import Swiper, { SwiperOptions } from 'swiper';
...
@Component({
tag: 'my-swiper-slider',
styleUrl: './styles.css',
assetsDirs: ['assets'],
shadow: true,
})
export class Carousel {
@Prop() options: SwiperOptions = {
slidesPerView: 3,
spaceBetween: 40,
autoplay: false,
loop: false,
autoHeight: true,
breakpoints: {
640: {
slidesPerView: 5,
spaceBetween: 20,
},
768: {
slidesPerView: 5,
spaceBetween: 40,
},
1024: {
slidesPerView: 5,
spaceBetween: 50,
},
}
}
private setSwiper() {
this.swiper = new Swiper('.swiper-container', this.options);
}
componentDidLoad() {
this.setSwiper();
}
render() {
return (
<Host class={{"container": true}}>
<PrevBtn
goBack={this.goBack.bind(this)} />
<div class="swiper-container">
<div class="swiper-wrapper">
<slot></slot>
</div>
</div>
<NextBtn
goForward={this.goForward.bind(this)} />
</Host>
);
}
}
出于某种原因,当我将组件配置为“shadow:true”时,它无法访问模板或者是我的想法。