10000 v-on: support modifiers without expression (close #1451) · Aphasia-GitHub/vue@91d6eeb · GitHub
[go: up one dir, main page]

Skip to content

Commit 91d6eeb

Browse files
committed
v-on: support modifiers without expression (close vuejs#1451)
1 parent f6071f1 commit 91d6eeb

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

src/directive.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Directive.prototype._bind = function () {
106106
if (this._literal) {
107107
this.update && this.update(this.expression)
108108
} else if (
109-
this._watcherExp &&
109+
(this._watcherExp || this.modifiers) &&
110110
(this.update || this.twoWay) &&
111111
(!this.isLiteral || this._isDynamicLiteral) &&
112112
!this._checkStatement()

src/directives/on.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ module.exports = {
7474
},
7575

7676
update: function (handler) {
77+
// stub a noop for v-on with no value,
78+
// e.g. @mousedown.prevent
79+
if (!this._descriptor.raw) {
80+
handler = function () {}
81+
}
82+
7783
if (typeof handler !== 'function') {
7884
process.env.NODE_ENV !== 'production' && _.warn(
7985
'v-on:' + this.arg + '="' +

src/parsers/directive-new.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ exports.parse = function (s) {
8181
inSingle = inDouble = false
8282
curly = square = paren = 0
8383
lastFilterIndex = 0
84-
dir = {}
84+
dir = { raw: s }
8585

8686
for (i = 0, l = str.length; i < l; i++) {
8787
c = str.charCodeAt(i)

test/unit/specs/directives/on_spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@ if (_.inBrowser) {
126126
expect(prevented).toBe(true)
127127
})
128128

129+
it('prevent modifier with no value', function () {
130+
new Vue({
131+
el: el,
132+
template: '<a href="#123" @click.prevent>'
133+
})
134+
var hash = window.location.hash
135+
trigger(el.firstChild, 'click')
136+
expect(window.location.hash).toBe(hash)
137+
})
138+
129139
it('multiple modifiers working together', function () {
130140
var outer = jasmine.createSpy('outer')
131141
var prevented

0 commit comments

Comments
 (0)
0