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

Skip to content

Commit d1ab424

Browse files
committed
v-on: support modifiers without expression (close #1451)
1 parent 57852b5 commit d1ab424

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/directive.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Directive.prototype._bind = function () {
8888
if (this.literal) {
8989
this.update && this.update(descriptor.raw)
9090
} else if (
91-
this.expression &&
91+
(this.expression || this.modifiers) &&
9292
(this.update || this.twoWay) &&
9393
!this._checkStatement()
9494
) {

src/directives/public/on.js

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

6464
update: function (handler) {
65+
// stub a noop for v-on with no value,
66+
// e.g. @mousedown.prevent
67+
if (!this.descriptor.raw) {
68+
handler = function () {}
69+
}
70+
6571
if (typeof handler !== 'function') {
6672
process.env.NODE_ENV !== 'production' && _.warn(
6773
'v-on:' + this.arg + '="' +

test/unit/specs/directives/public/on_spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@ if (_.inBrowser) {
144144
expect(prevented).toBe(true)
145145
})
146146

147+
it('prevent modifier with no value', function () {
148+
new Vue({
149+
el: el,
150+
template: '<a href="#123" @click.prevent>'
151+
})
152+
var hash = window.location.hash
153+
trigger(el.firstChild, 'click')
154+
expect(window.location.hash).toBe(hash)
155+
})
156+
147157
it('multiple modifiers working together', function () {
148158
var outer = jasmine.createSpy('outer')
149159
var prevented

0 commit comments

Comments
 (0)
0