fix maintain attrs hook

This commit is contained in:
shibao 2022-03-04 22:56:52 -05:00
parent 0309e9d714
commit 9f2cc54738
1 changed files with 4 additions and 1 deletions

View File

@ -2,7 +2,10 @@
// update. https://github.com/phoenixframework/phoenix_live_view/issues/1011
export default {
attrs () { return this.el.getAttribute('data-attrs').split(', ') },
attrs() {
const attrs = this.el.getAttribute('data-attrs');
if (attrs) { return attrs.split(', '); } else { return []; }
},
beforeUpdate () { this.prevAttrs = this.attrs().map(name => [name, this.el.getAttribute(name)]) },
updated () { this.prevAttrs.forEach(([name, val]) => this.el.setAttribute(name, val)) }
}