Coder Social home page Coder Social logo

pspgbhu / vue-swipe-mobile Goto Github PK

View Code? Open in Web Editor NEW
98.0 5.0 25.0 1.46 MB

😃 A siwpe (touch slider) component for Vue2

License: MIT License

JavaScript 48.27% Vue 49.49% HTML 1.50% Shell 0.74%
vue swipe slider slide c-swipe vue-swipe vue-swiper swiper c-swiper

vue-swipe-mobile's Introduction

English | 简体中文

c-swipe

gzip npm package NPM downloads GitHub issues Travis

NPM

A swipe (touch slide) component for Vue2.x in mobile device. Only support touch event now.

c-swipe

Install

npm install c-swipe --save

Usage

register components:

// main.js

// import c-swipe files into main.js
import 'c-swipe/dist/swipe.css';
import { Swipe, SwipeItem } from 'c-swipe';

// global register components
Vue.component('swipe', Swipe);
Vue.component('swipe-item', SwipeItem);

Use in .vue files.

<swipe
  v-model="index"
  style="text-align: center; line-height: 80px; height: 100px; background: #42b983;"
>
  <swipe-item style="height: 100px; line-height: 100px">item1</swipe-item>
  <swipe-item style="height: 100px; line-height: 100px">item2</swipe-item>
  <swipe-item style="height: 100px; line-height: 100px">item3</swipe-item>
</swipe>
new Vue({
  data: function () {
    return {
      index: 0, // two way
    };
  },
});

Or, you want import it by html tag

<link href="https://unpkg.com/c-swipe/dist/swipe.css" rel="stylesheet"></head>
<script type="text/javascript" src="https://unpkg.com/c-swipe/dist/swipe.js"></script>
var vueSwipe = swipe.Swipe;
var vueSwipeItem = swipe.SwipeItem;

new Vue({
  el: 'body',
  // register components
  components: {
    'swipe': vueSwipe,
    'swipe-item': vueSwipeItem
  }
  // ...
  // ...
});

Options

Option Type Defalut Description
v-model Number 0 The value binding index of swipe-item
pagination Boolean true If need default pagination.
loop Boolean true loop move
autoplayTime Number 0 ms. Interval time of change card. The card will not auto change when this value is equal to 0
speed Number 300 ms, the spend time of change card.
minMoveDistance String '20%' Such as '20%', '80px'. The minimum distance that trigger to change card

Methods

  • swipe.reset()

The c-swipe internally recalculates the width of the Swipe and calculates the scroll distance based on the new width. This solves the problem that the c-swipe scroll distance is not correct after the container is resized.

Example:

<swipe ref="swipe">
  <swipe-item>item1</swipe-item>
  <swipe-item>item2</swipe-item>
  <swipe-item>item3</swipe-item>
</swipe>

<script>
  export default {
    // ...
    // ...

    mounted() {
      // Avoid losing context
      this.handleResize = this.handleResize.bind(this);
      window.addEventListener('resize', this.handleResize);
    },

    destroyed() {
      window.removeEventListener('resize', this.handleResize);
    },

    methods: {
      handleResize() {
        this.$refs.swipe.reset();
      },
    },

    // ...
    // ...
  }
</script>

Preview

Scan the QR code below to preview

c-swpie

License

MIT

vue-swipe-mobile's People

Contributors

dependabot[bot] avatar pspgbhu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

vue-swipe-mobile's Issues

异步获取图片报错

chrome console:
vue.esm.js?65d7:479 [Vue warn]: Error in mounted hook: "TypeError: Cannot read property 'parentNode' of undefined"

found in

---> at /Users/--/Documents/wap/vue_mobile/vue_mobile/src/components/swiper/swiper.vue
at /Users/--/Documents/wap/vue_mobile/vue_mobile/src/components/home/Home.vue
at /Users/--/Documents/wap/vue_mobile/vue_mobile/src/App.vue

TypeError: Cannot read property 'parentNode' of undefined
at VueComponent.mounted (swiper.vue?5c0e:142)
at callHook (vue.esm.js?65d7:2665)
at Object.insert (vue.esm.js?65d7:3526)
at invokeInsertHook (vue.esm.js?65d7:5469)
at Vue$3.patch [as patch] (vue.esm.js?65d7:5639)
at Vue$3.Vue._update (vue.esm.js?65d7:2414)
at Vue$3.updateComponent (vue.esm.js?65d7:2538)
at Watcher.get (vue.esm.js?65d7:2881)
at new Watcher (vue.esm.js?65d7:2870)
at mountComponent (vue.esm.js?65d7:2542)

*.vue:
<swiper v-model="index" style="text-align: center; line-height: 80px; height: 100px;"> <swiper-item style="height: 100px;" v-for="(item, index) in items" :key="index"> <img :src="imgDomain+item.ImgUrl" > </swiper-item> </swiper>

遍历问题

这个组件拿动态数据的时候怎么做

图片数量小于等于2个时容易出现bug

当图片为1张时,滑动后很容易卡住在两个图片之间
当图片为2张时,右滑正常,左滑很容易滚回去
因为项目的原因,图片数量在1~3张之间,也有可能是我打开的姿势不对

建议 、插件优化

你好,某些原因,借鉴了你的代码,发现一个问题,就是autoplayTime设置之后,如果页面跳转,你这没有清除定时autoplayTimer,导致页面报错,希望作者可以在swpie组件销毁的时候清除一下,避免插件报错

在第1个和最后1个切换时,会出现空白

_447c36eb-422f-4f36-87de-1a7b1a1994bb

如图,两边的copy元素是空的,无论是手动切换还是自动轮播,都会出现瞬间的空白,没使用别的配置,就下面的两个:

<Swipe :pagination="false" :autoplayTime="1000">
</Swipe>

谢谢!

页面内部引用css,注册组件,会有报错。

win10 chrome 最新版浏览器
TypeError: Cannot read property 'filter' of undefined
at VueComponent.initDatas (swipe.js:1)
at VueComponent.init (swipe.js:1)
at VueComponent.mounted (swipe.js:1)
at callHook (vue.runtime.esm.js:2917)
at Object.insert (vue.runtime.esm.js:4154)
at invokeInsertHook (vue.runtime.esm.js:5956)
at VueComponent.patch [as patch] (vue.runtime.esm.js:6175)
at VueComponent.Vue._update (vue.runtime.esm.js:2666)
at VueComponent.updateComponent (vue.runtime.esm.js:2784)
at Watcher.get (vue.runtime.esm.js:3138)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.