vuejs slick is not working with v-for(vuejs slick 不适用于 v-for)
问题描述
vue-slick 可以很好地处理静态内容.但是当我试图循环播放 user.slick 的播放列表时,它不起作用.
vue-slick is working fine with static content. But when I am trying to loop through playlists of user.slick is not working.
html部分:
<template>
<slick ref="slickone" :options="slickOptions">
<div v-for='playlist in user_playlists'>
<a href="#">
<img :src="cGxheWxpc3QuaW1hZ2U=">
<p>Playlist Name</p>
</a>
</div>
</slick>
</template>
脚本部分:
<script>
import Slick from 'vue-slick';
import './node_modules/slick-carousel/slick/slick.css';
import './node_modules/slick-carousel/slick/slick-theme.css';
export default {
data() {
return {
user_playlists: [],
slickOptions: {
infinite: true,
slidesToShow: 5,
slidesToScroll: 1,
autoplaySpeed: 5e3,
},
};
},
methods: {
getUserPlaylists() {
this.$http.get('api/user_playlists/user-playlists')
.then(response => {
this.user_playlists = response.body.data;
this.$refs.slickone.reSlick();
});
},
updated() {
this.reInit();
},
reInit() {
this.$refs.slickone.reSlick();
},
},
components: {
'slick': Slick,
},
watch: {
profileData() {
this.getUserPlaylists();
},
user_playlists() {
this.reInit();
}
}
}
</script>
我检查了文档并使用了 this.$ref.slickone.reSlick()
但它仍然无法正常工作.
I have checked the documentation and used this.$ref.slickone.reSlick()
but still it's not working.
推荐答案
我也有类似的问题,但是我只更新了一次状态.对我来说解决方案是:
I have a similar problem, but I update the state only once. For me solution is:
beforeUpdate() {
if (this.$refs.slick) {
this.$refs.slick.destroy();
}
},
updated() {
this.$nextTick(function () {
if (this.$refs.slick) {
this.$refs.slick.create(this.slickOptions);
}
});
},
也许这会对你有所帮助.
Maybe this will help you.
这篇关于vuejs slick 不适用于 v-for的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:vuejs slick 不适用于 v-for


- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01