Skip to content

Commit 8e4ca2f

Browse files
committed
Make sure this.$el is stable
1 parent b1d371c commit 8e4ca2f

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

index.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@ export default {
44
name: 'github-button',
55
props: ['href', 'ariaLabel', 'title', 'dataIcon', 'dataSize', 'dataShowCount', 'dataText'],
66
render: function (h) {
7-
return h('a', { attrs: {
8-
'href': this.href,
9-
'aria-label': this.ariaLabel,
10-
'title': this.title,
11-
'data-icon': this.dataIcon,
12-
'data-size': this.dataSize,
13-
'data-show-count': this.dataShowCount,
14-
'data-text': this.dataText
15-
} }, this.$slots.default)
7+
return h('span', [
8+
h('a', {
9+
attrs: {
10+
'href': this.href,
11+
'aria-label': this.ariaLabel,
12+
'title': this.title,
13+
'data-icon': this.dataIcon,
14+
'data-size': this.dataSize,
15+
'data-show-count': this.dataShowCount,
16+
'data-text': this.dataText
17+
},
18+
ref: '_'
19+
}, this.$slots.default)
20+
])
1621
},
1722
mounted: function () {
1823
this.paint()
@@ -28,16 +33,15 @@ export default {
2833
},
2934
methods: {
3035
paint: function () {
31-
(function ($el, _) {
32-
render($el.parentNode.insertBefore(_, $el).appendChild($el), function (el) {
33-
try {
34-
_.replaceChild(el, $el)
35-
} catch (_) {}
36-
})
37-
})(this.$el, this._ = document.createElement('span'))
36+
var _ = this.$el.appendChild(document.createElement('span'))
37+
render(_.appendChild(this.$refs._), function (el) {
38+
try {
39+
_.parentNode.replaceChild(el, _)
40+
} catch (_) {}
41+
})
3842
},
3943
reset: function () {
40-
this._.parentNode.replaceChild(this.$el, this._)
44+
this.$el.replaceChild(this.$refs._, this.$el.lastChild)
4145
}
4246
}
4347
}

0 commit comments

Comments
 (0)