瀏覽代碼

Scope the change until after data methods are reactive

Kevin Batdorf 4 年之前
父節點
當前提交
39aee36458
共有 1 個文件被更改,包括 3 次插入1 次删除
  1. 3 1
      src/component.js

+ 3 - 1
src/component.js

@@ -22,8 +22,10 @@ export default class Component {
             $el: this.$el,
         }
 
+        let canonicalComponentElementReference = componentForClone ? componentForClone.$el : this.$el
+
         Object.entries(Alpine.magicProperties).forEach(([name, callback]) => {
-            Object.defineProperty(dataExtras, `$${name}`, { get: function () { return callback(this.$el) } });
+            Object.defineProperty(dataExtras, `$${name}`, { get: function () { return callback(canonicalComponentElementReference) } });
         })
 
         this.unobservedData = componentForClone ? componentForClone.getUnobservedData() : saferEval(dataExpression, dataExtras)