简体   繁体   English

是否可以在 vue 组件中使用 glidejs?

[英]Is it possible to use glidejs inside a vue component?

I would like to use glidejs inside a vuejs component, although I couldn't make it work so far.我想在vuejs组件中使用glidejs ,尽管到目前为止我还不能让它工作。

Is it possible to achieve this?有可能实现这一目标吗? Does vuejs support such a thing? vuejs支持这样的东西吗?

my code:我的代码:

<template>
    <div>
        <div class="glide">
            <div class="glide__track" data-glide-el="track">
                <ul class="glide__slides">
                    <li class="glide__slide">0</li>
                    <li class="glide__slide">1</li>
                    <li class="glide__slide">2</li>
                </ul>
            </div>
            <div class="glide__arrows" data-glide-el="controls">
                <button class="glide__arrow glide__arrow--left" data-glide-dir="<">prev</button>
                <button class="glide__arrow glide__arrow--right" data-glide-dir=">">next</button>
            </div>
        </div>
    </div>
</template>

<script>
import Glide from '@glidejs/glide'
new Glide('.glide').mount() // this is probably wrong
    export default {
        name: 'Carousel',
    }
</script>

<style scoped>
    @import '../assets/styles/glide/glide.core.min.css';
</style>

The main fix needed in your code is to move the Glide initialization to the mounted() hook , which runs when the component has mounted in the document, enabling the .glide selector given to the Glide constructor to be found:代码中需要的主要修复是将Glide初始化移动到mounted()钩子,该钩子在组件已挂载到文档中时运行,从而能够找到提供给Glide构造函数的.glide选择器:

<script>
import Glide from '@glidejs/glide'

export default {
  mounted() {
    new Glide('.glide').mount()
  },
}
</script>

demo 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM