Vue Tiny Slider

1.1.0 · active · verified Sun Apr 19

Vue Tiny Slider is a Vue.js wrapper component for the vanilla JavaScript `tiny-slider` library by ganlanyuan, designed to provide a lightweight and highly customizable carousel solution. The current stable version, 1.1.0, is built for Vue 3.x applications, while older Vue 2.x projects should use versions 0.1.x. The library differentiates itself by providing a direct and comprehensive exposure of `tiny-slider`'s extensive options as Vue props, along with access to the underlying slider instance's methods via template refs. This approach ensures maximum flexibility and control over the slider's behavior without abstracting away the core `tiny-slider` API. It ships with TypeScript types and includes specific guidance for handling Server-Side Rendering (SSR) environments, particularly with Nuxt 3, addressing potential DOM-related issues.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to globally register and locally use `vue-tiny-slider`, including passing options as props, importing necessary styles, and accessing underlying `tiny-slider` methods via template refs.

import { createApp, ref, onMounted } from 'vue';
import VueTinySlider from 'vue-tiny-slider';
import 'tiny-slider/src/tiny-slider.scss'; // Don't forget to import styles!

const App = {
  components: { 'tiny-slider': VueTinySlider },
  template: `
    <div id="app">
      <h1>My Awesome Carousel</h1>
      <tiny-slider :mouse-drag="true" :loop="false" :items="2" :gutter="20" ref="mySlider">
        <div>Slider item #1</div>
        <div>Slider item #2</div>
        <div>Slider item #3</div>
        <div>Slider item #4</div>
        <div>Slider item #5</div>
        <div>Slider item #6</div>
      </tiny-slider>
      <button @click="goToNextSlide">Next Slide</button>
    </div>
  `,
  setup() {
    const mySlider = ref(null);

    const goToNextSlide = () => {
      if (mySlider.value && mySlider.value.slider) {
        mySlider.value.slider.goTo('next');
      } else {
        console.warn('Slider instance not available yet.');
      }
    };

    // Example of accessing slider info after mount
    onMounted(() => {
      if (mySlider.value && mySlider.value.slider) {
        console.log('Slider initialized:', mySlider.value.slider.getInfo());
      }
    });

    return { mySlider, goToNextSlide };
  }
};

createApp(App).mount('#app');

view raw JSON →