8000 html · bencode/vue@2ca10c2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2ca10c2

Browse files
committed
html
1 parent a5e8ed0 commit 2ca10c2

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/directives/public/html.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,47 @@
1-
var _ = require('../../util')
21
import { parseTemplate } from '../../parsers/template'
2+
import {
3+
createAnchor,
4+
before,
5+
replace,
6+
remove,
7+
_toString,
8+
toArray
9+
} from '../../util'
310

4-
module.exports = {
11+
export default {
512

6-
bind: function () {
13+
bind () {
714
// a comment node means this is a binding for
815
// {{{ inline unescaped html }}}
916
if (this.el.nodeType === 8) {
1017
// hold nodes
1118
this.nodes = []
1219
// replace the placeholder with proper anchor
13-
this.anchor = _.createAnchor('v-html')
14-
_.replace(this.el, this.anchor)
20+
this.anchor = createAnchor('v-html')
21+
replace(this.el, this.anchor)
1522
}
1623
},
1724

18-
update: function (value) {
19-
value = _._toString(value)
25+
update (value) {
26+
value = _toString(value)
2027
if (this.nodes) {
2128
this.swap(value)
2229
} else {
2330
this.el.innerHTML = value
2431
}
2532
},
2633

27-
swap: function (value) {
34+
swap (value) {
2835
// remove old nodes
2936
var i = this.nodes.length
3037
while (i--) {
31-
_.remove(this.nodes[i])
38+
remove(this.nodes[i])
3239
}
3340
// convert new value to a fragment
3441
// do not attempt to retrieve from id selector
3542
var frag = parseTemplate(value, true, true)
3643
// save a reference to these nodes so we can remove later
37-
this.nodes = _.toArray(frag.childNodes)
38-
_.before(frag, this.anchor)
44+
this.nodes = toArray(frag.childNodes)
45+
before(frag, this.anchor)
3946
}
4047
}

0 commit comments

Comments
 (0)
0