Skip to content

Commit f4272b3

Browse files
committed
修改在路由上使用v-tap event is not defined 的bug
1 parent e135a6f commit f4272b3

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

test/test-click.html

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title></title>
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
7+
<script src="https://unpkg.com/vue/dist/vue.js"></script>
8+
<script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
9+
<script src="../vue-tap.js"></script>
10+
</head>
11+
<body>
12+
<div id="app">
13+
<h1>Hello App</h1>
14+
<p>
15+
<router-link to="/home" v-tap>go to Home</router-link>
16+
<router-link to="/about">go to About</router-link>
17+
</p>
18+
19+
<router-view></router-view>
20+
</div>
21+
22+
23+
<script>
24+
25+
var Home = Vue.extend({
26+
template: '<div><h1><p>{{msg}}</p></h1></div>',
27+
data: function () {
28+
return {
29+
msg: 'hello world!'
30+
}
31+
}
32+
});
33+
34+
var About = Vue.extend({
35+
template: '<div><h1>About</h1><p> This is the tutorial about vue-router. </p></div>'
36+
})
37+
38+
var router = new VueRouter({
39+
routes: [
40+
{path: '/home', component: Home},
41+
{path: '/about', component: About},
42+
]
43+
})
44+
45+
new Vue({
46+
router
47+
}).$mount("#app");
48+
</script>
49+
</body>
50+
51+
</html>

vue-tap.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,19 @@
126126
el.tapObj = {};
127127
el.handler = function (e,isPc) { //This directive.handler
128128
var value = binding.value;
129+
130+
if (!value && el.href && !binding.modifiers.prevent) {
131+
return window.location = el.href;
132+
}
133+
129134
value.event = e;
130135
var tagName = value.event.target.tagName.toLocaleLowerCase();
131136
!isPc ? value.tapObj = el.tapObj : null;
132137

133138
if(tagName === 'input' || tagName === 'textarea') {
134139
return value.event.target.focus();
135140
}
136-
if (!value && el.href && !binding.modifiers.prevent) {
137-
return window.location = el.href;
138-
}
141+
139142
value.methods.call(this, value);
140143
};
141144
if (isPc()) {

0 commit comments

Comments
 (0)