简体   繁体   English

如何在另一个组件中使用Slick.js方法-Vue

[英]How to use the Slick.js method in another component - Vue

I'm new in Vue and tries to run the "next" method of the Slider component, after clicking the button in the Navigation component. 我是Vue的新手,在单击“导航”组件中的按钮后,尝试运行Slider组件的“下一个”方法。 I tried to make a mixin, but without a result. 我试图做一个混合,但没有结果。

Slider component 滑块组件

<template>
  <slick ref="slick" :options="slickOptions">
   ...images
  </slick>
</template>

<script>
  import Slick from 'vue-slick';

  export default {
    name: 'Slider',
    components: {
      'slick': Slick
    },
    data() {
      return {
        slickOptions: {
          infinite: true,
          centerMode: true,
          centerPadding: '90px',
          slidesToShow: 1,
          arrows: false,
          dots: false
        }
      };
    },
    methods: {
      next() {
        this.$refs.slick.next();
      },
      prev() {
        this.$refs.slick.prev();
      }
    }
  };
</script>

Navigation component 导航组件

<template>
  <button @click="next()">
    <img src="button.url" alt="button.alt">
  </button>
</template>

To invoke a method on a component using $refs you have to set the ref property. 要使用$refs在组件上调用方法,您必须设置ref属性。 Have you set it? 你设置好了吗?

<slick ref="slick" :options="slickOptions"></slick>

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

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