Skip to content

JamesZXCVBNM/vue-swipy

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vue-Swipy

Vue swipeable component for Tinder-like apps.

🚀 See live demo

Installation

npm install vue-swipy

Usage

<template>
  <div id="app">
    <Swipeable
      v-for="card in cards"
      :key="card.id"
      v-on:swipe="onSwipe"
      :style="{
        position: 'absolute',
        height: '400px',
        width: '250px',
        background: card.color,
        borderRadius: '8px',
      }"
    />
  </div>
</template>

<script>
  import { Swipeable } from "vue-swipy";

  function getRandomColor() {
    var letters = "0123456789ABCDEF";
    var color = "#";
    for (var i = 0; i < 6; i++) {
      color += letters[Math.floor(Math.random() * 16)];
    }
    return color;
  }

  export default {
    name: "App",
    components: {
      Swipeable,
    },
    data() {
      return { cards: [] };
    },
    mounted() {
      this.cards.push({ id: Math.random(), color: getRandomColor() });
      this.cards.push({ id: Math.random(), color: getRandomColor() });
      this.cards.push({ id: Math.random(), color: getRandomColor() });
    },
    methods: {
      onSwipe(direction) {
        console.log(direction);
        setTimeout(() => {
          this.cards.pop();
          this.cards.unshift({ id: Math.random(), color: getRandomColor() });
        }, 300);
      },
    },
  };
</script>

<style>
  body {
    margin: 0;
  }
  #app {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    width: 100vw;
  }
</style>

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Vue 98.3%
  • JavaScript 1.7%