vue.js - Swiper 无法使用 vue.js 处理 Framework7 中的动态数据

标签 vue.js html-framework-7

我在我的应用程序中使用 Framework7 swiper。当我使用静态数据时,swiper 工作正常,但当我使用 Web 服务从服务器获取数据时,它无法工作。 我已经使用 DOM 来更新 swiper 但不幸的是,它没有更新。请给我更新刷卡器的解决方案。

我的代码是:

<script>
export default {
    data() {
        return {
            posts: [],
        }
    },

    methods: {
        onF7Init:function() {
            this.theater();   
        },

        // function of fetch the data from serve:
        theater: function() {
            // fetch images path from server
            axios.get(`https://api.themoviedb.org/3/discover/movie?api_key={api_key}&primary_release_date.gte=2018-02-1&primary_release_date.lte=2018-02-21`)
                .then(response => {
                    current.**posts** = response.data.results;

                //I added this line to update the swiper:
                $$(this).find('#banner-swiper')[0].swiper.update();
            })
        }
    }
}
</script>

我添加了这一行来更新刷卡器:

$$(this).find('#banner-swiper')[0].swiper.update()

我的应用程序模板:

<f7-swiper pagination id="banner-swiper">

    <f7-swiper-slide  v-for="
     (post,index) in posts" :key="index" >              

         <img :src="'https://image.tmdb.org/t/p/w500' + 
            post.backdrop_path"/>
    </f7-swiper-slide>
</f7-swiper>

最佳答案

您可以尝试使用以下代码来更新您的swiper

this.$$(".swiper-container")[0].swiper.update();

如果您在单个页面中使用超过 1 个 swiper,则可以将 [0] 替换为 swiper 的索引,或者您可以使用Framework7 API来更新您的Swiper。

let swiper = this.$f7.swiper.get(".banner-swiper");
swiper.$el[0].swiper.update();

这两种解决方案都适合我。

关于vue.js - Swiper 无法使用 vue.js 处理 Framework7 中的动态数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49231779/

相关文章:

javascript - DOM修改后如何找到scrollTop

javascript - 框架7 : Navbar hidden when I'm move to anothers views

javascript - 如何在 Framework7 中移动到另一个页面(导出变量)?

vue.js - 使用 Framework7+Vue 的 smart-select 和 v-model

javascript - 在 API 错误时打破 Vuex 操作中的 promise

javascript - 将动态 ID 传递给 router_link - Vue.js

vuejs2 - VueJS - 构建后 dist 中的多个 js 文件

javascript - 导航时点击框架 7 不起作用

vue.js - 如何将自定义 Vue 组件安装到 L.markerClusterGroup 的标记

javascript - vue.js - v-html 替代方案