SwipeItem.vue 717 Bytes
Newer Older
Nature's avatar
Nature committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
<template>
  <section :class="c()" :style="style">
    <slot/>
  </section>
</template>

<script>
import { base } from '../../common/mixins'

export default {
  name: 'SwipeItem',
  mixins: [ base ],

  data () {
    return {
      offset: 0,
    }
  },
  computed: {
    style () {
      const { vertical, width, height } = this.$parent

      return {
        width: width + 'px',
        height: vertical ? height + 'px' : '100%',
        transform: `translate${vertical ? 'Y' : 'X'}(${this.offset}px)`,
      }
    },
  },
  mounted () {
    this.$parent && this.$parent.swipes.push(this)
  },
  destroyed () {
    this.$parent && this.$parent.swipes.splice(this.$parent.swipes.indexOf(this), 1)
  },
}
</script>