Skip to content

Commit

Permalink
feat: 支持在浏览器引入情况下, 自动挂在指令
Browse files Browse the repository at this point in the history
  • Loading branch information
any86 committed Apr 12, 2019
1 parent e66bde9 commit 424544f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
12 changes: 10 additions & 2 deletions example/vue/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
<main id="app">
<div
v-touch:pan-config="{abc:123}"
v-touch:pan="panHandler"
v-touch:tap="tapHandler"
v-touch:pan.prevent="panHandler"
@tap.prevent="tapHandler"
@click="clickHandler"
v-touch:swipe="swipeHandler"
class="box">{{msg}}</div>
</main>
Expand All @@ -35,10 +36,17 @@
el: '#app',
data() {
return {
anyTouch:null,
msg: 1234567890
};
},
mounted(){

},
methods: {
clickHandler(){
console.log('click');
},
swipeHandler(ev){
console.log(ev.type);
},
Expand Down
11 changes: 7 additions & 4 deletions src/vueDirective/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ const plugin = {
}
// 匹配手势, 无"-""
else if (/^((?!-).)*$/.test(binding.arg)) {
console.log(binding.modifiers);
// 绑定事件
instance.on(binding.arg, (ev: Computed) => {
if (!!binding.modifiers.preventDefault) {
ev.preventDefault();
if(binding.modifiers.prevent) {
ev.preventDefault();
}
}
// if (binding.modifiers.self && el !== e.target) return;
binding.value(ev);
Expand Down Expand Up @@ -68,8 +71,8 @@ const plugin = {
};

// 自动加载插件
// if (typeof <any>window !== 'undefined' && (<any>window).Vue) {
// (<any>window).Vue.use(plugin);
// };
if (typeof <any>window !== 'undefined' && (<any>window).Vue) {
(<any>window).Vue.use(plugin);
};

export default plugin;

0 comments on commit 424544f

Please sign in to comment.