Skip to content

Commit 9ec0259

Browse files
committed
v-model for content editable
1 parent 9a132a9 commit 9ec0259

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/directives/model.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,25 @@ module.exports = {
77

88
var self = this,
99
el = self.el,
10-
type = el.type
10+
type = el.type,
11+
tag = el.tagName
1112

1213
self.lock = false
1314

1415
// determine what event to listen to
1516
self.event =
1617
(self.compiler.options.lazy ||
17-
el.tagName === 'SELECT' ||
18-
type === 'checkbox' ||
19-
type === 'radio')
18+
tag === 'SELECT' ||
19+
type === 'checkbox' || type === 'radio')
2020
? 'change'
2121
: 'input'
2222

2323
// determin the attribute to change when updating
24-
var attr = type === 'checkbox'
24+
var attr = self.attr = type === 'checkbox'
2525
? 'checked'
26-
: 'value'
26+
: (tag === 'INPUT' || tag === 'SELECT' || tag === 'TEXTAREA')
27+
? 'value'
28+
: 'innerHTML'
2729

2830
// attach listener
2931
self.set = self.filters
@@ -97,7 +99,7 @@ module.exports = {
9799
} else if (el.type === 'checkbox') { // checkbox
98100
el.checked = !!value
99101
} else {
100-
el.value = utils.toText(value)
102+
el[self.attr] = utils.toText(value)
101103
}
102104
},
103105

0 commit comments

Comments
 (0)