Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

为长按事件增加参数,修改了默认调用指令方法为对象形式 #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 32 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,42 @@ import vueTouch from 'kim-vue-touch'
Vue.use(vueTouch)

```
* kim-vue-touch提供了点击、长按、左滑、右滑、上滑、下滑等事件,
* 当你不需要传参时可以通过v-tap="vueTouch"的形式调用方法,
* 当你需要传参时v-tap="(e)=>vueTouch('点击',e)"的方式调用,e是event对象
* 当指令搭配v-for使用时,一定要确保key值的唯一性,否则不能保证数据刷新之后事件被重新绑定(参考vue就地复用机制)
* 尽量避免对数组、对象的直接赋值操作,可能会导致参数不更新

- kim-vue-touch 提供了点击、长按、左滑、右滑、上滑、下滑等事件,
- 指令 v-touchall='touchOption'
- touchOption 可分别配置启用哪些操作(如点击、长按、滑动,及其回调函数),以及长按延时,见 demo
- 当指令搭配 v-for 使用时,一定要确保 key 值的唯一性,否则不能保证数据刷新之后事件被重新绑定(参考 vue 就地复用机制)
- 尽量避免对数组、对象的直接赋值操作,可能会导致参数不更新

```
<template>
<div class="box"
v-tap="(e)=>vueTouch('点击',e)"
v-longtap="(e)=>vueTouch('长按',e)"
v-swipeleft="(e)=>vueTouch('左滑',e)"
v-swiperight="(e)=>vueTouch('右滑',e)"
v-swipeup="(e)=>vueTouch('上滑',e)"
v-swipedown="(e)=>vueTouch('下滑',e)"
></div>
<div id="app">
<div class="box" v-touchall="touchOption">{{ name }}</div>
</div>
</template>
<script>
export default {
name: 'App',
data () {
return {
name:'touch',
}
},
methods:{
vueTouch:function(txt,e){
this.name = txt;
}
}
export default {
name: "App",
data() {
return {
name: "touch",
touchOption: {
tap: e => this.vueTouch("点击", e),
longtap: e => this.vueTouch("长按", e),
swipeleft: e => this.vueTouch("左滑", e),
swiperight: e => this.vueTouch("右滑", e),
swipeup: e => this.vueTouch("上滑", e),
swipedown: e => this.vueTouch("下滑", e),

longtapDelay: 500
}
};
},
methods: {
vueTouch: function(txt, e) {
this.name = txt;
}
}
};
</script>
```
```
84 changes: 44 additions & 40 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,53 +1,57 @@
<template>
<div id="app">
<div class="box"
v-tap="(e)=>vueTouch('点击',e)"
v-longtap="(e)=>vueTouch('长按',e)"
v-swipeleft="(e)=>vueTouch('左滑',e)"
v-swiperight="(e)=>vueTouch('右滑',e)"
v-swipeup="(e)=>vueTouch('上滑',e)"
v-swipedown="(e)=>vueTouch('下滑',e)"
>
{{ name }}
</div>
</div>
<div id="app">
<div class="box" v-touchall="touchOption">{{ text }}</div>
</div>
</template>

<script>
export default {
name: 'App',
data () {
return {
name:'touch',
}
},
methods:{
vueTouch:function(txt,e){
this.name = txt;
}
}
}
name: "App",
data() {
return {
text: "touch",
touchOption: {
tap: e => this.vueTouch("点击", e),
doubletap: e => this.vueTouch("双击", e),
longtap: e => this.vueTouch("长按", e),
swipeleft: e => this.vueTouch("左滑", e),
swiperight: e => this.vueTouch("右滑", e),
swipeup: e => this.vueTouch("上滑", e),
swipedown: e => this.vueTouch("下滑", e),
doubletapDelay: 300,
longtapDelay: 600
}
};
},
methods: {
vueTouch: function(txt, e) {
this.text = txt;
}
}
};
</script>

<style>
html,body{
width: 100%;
height: 100%;
html,
body {
width: 100%;
height: 100%;
margin: 0;
}
#app {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.box{
width: 300px;
height: 300px;
background-color: red;
color: #FFFFFF;
text-align: center;
line-height: 300px;
font-size: 100px;
.box {
width: 300px;
height: 300px;
background-color: red;
color: #ffffff;
text-align: center;
line-height: 300px;
font-size: 100px;
}
</style>
Loading