javascript - Vue Owl Carousel 在容器外渲染数据
问题描述
我需要帮助,我的 vue-owl-carousel 库正在容器外渲染我的 vue js 数据,但是当我手动输入数据时它工作正常,这是我的代码到目前为止:
输入:
<carousel class="mb-2" :dots="false" :nav="false" :responsive="responsiveT1" :items="3">
<div class="mx-1 item" v-for="(brand,index) in brands" :key="index">
<img class="brand-image" :src="brand.url" @click="redirect(brand.slug)"/>
</div>
</carousel>
输出:
<div id="carousel_s4nwluywy5e" class="owl-carousel owl-theme owl-loaded owl-drag">
<div class="owl-stage-outer">
<div class="owl-stage"></div>
</div>
<div class="owl-nav disabled">
<div class="owl-prev">next</div>
<div class="owl-next">prev</div>
</div>
<div class="owl-dots disabled"></div>
<div class="mx-1 item">
<img src="storage/sample.jpg" class="brand-image">
</div>
<div class="mx-1 item">
<img src="storage/sample.jpg" class="brand-image">
</div>
<div class="mx-1 item">
<img src="storage/sample.jpg" class="brand-image">
</div>
</div>
预期输出:
<div id="carousel_s4nwluywy5e" class="owl-carousel owl-theme owl-loaded owl-drag">
<div class="owl-stage-outer">
<div class="owl-stage">
<div class="mx-1 item">
<img src="storage/sample.jpg" class="brand-image">
</div>
<div class="mx-1 item">
<img src="storage/sample.jpg" class="brand-image">
</div>
<div class="mx-1 item">
<img src="storage/sample.jpg" class="brand-image">
</div>
</div>
</div>
<div class="owl-nav disabled">
<div class="owl-prev">next</div>
<div class="owl-next">prev</div>
</div>
<div class="owl-dots disabled"></div>
</div>
先谢谢各位了!
解决方案
也许你必须在你的 axios 或 ajax API 调用之前销毁 carrousel,如下所示:
$('.yourSelector').trigger('destroy.owl.carousel');
一旦你得到数据结果,你就可以使用updated()
vuejs lifeCycle 和$nextTick
hook 这样的方式来初始化 owl carousel:
updated() {
this.$nextTick(function () {
$('.yourSelector').owlCarousel({
loop: false,
rewind: true,
margin:10,
nav:true,
...
)}
})
}
推荐阅读
- python - 按第n个字符python从字符串中拆分字符
- java - Toast 消息不显示?
- email - 如何使用脚本在 Outlook 中将电子邮件合并并转发到单个电子邮件中?
- ios - 使用 swift 代码对两个视图进行约束
- python - 如何将深度嵌套的 JSON 读入数据框?
- dataframe - 如何使用 pyspark 将 null 分配给配置单元表列
- cuda - 设备 -> 主机与主机 -> cuda 中的设备复制性能
- kubernetes - Kubernetes 在部署容器中运行 shell 命令
- python - sqlalchemy 列出连接池内的连接
- node.js - 使用 Node.js 和 Cheerio 抓取新用户问题