Browse Source

[ui] Vue 3 - Non string props/attributes were not passed to web components properly, fixed that

sreenaths 4 năm trước cách đây
mục cha
commit
6301488d91

+ 6 - 5
desktop/core/src/desktop/js/ko/bindings/ko.vue.js

@@ -16,23 +16,24 @@
 
 import * as ko from 'knockout';
 
-function setAttributes(el, attrs) {
-  for (const key in attrs) {
-    el.setAttribute(key, attrs[key]);
+function setProps(el, props) {
+  for (const key in props) {
+    el.setAttribute(key, props[key]);
   }
+  Object.assign(el, props);
 }
 
 ko.bindingHandlers.vueKoProps = {
   init: (element, valueAccessor) => {
     const data = valueAccessor();
-    setAttributes(element, data);
+    setProps(element, data);
   }
 };
 
 ko.bindingHandlers.vueProps = {
   init: (element, valueAccessor) => {
     const data = valueAccessor();
-    setAttributes(element, ko.toJS(data));
+    setProps(element, ko.toJS(data));
   }
 };
 

+ 7 - 1
desktop/core/src/desktop/js/vue/wrapper/index.ts

@@ -155,7 +155,13 @@ export default function wrap(
 
     syncAttribute(key: string): void {
       const camelized = camelize(key);
-      const value = this.hasAttribute(key) ? this.getAttribute(key) : undefined;
+      let value = undefined;
+
+      if (this.hasOwnProperty(key)) {
+        value = this[key];
+      } else if (this.hasAttribute(key)) {
+        value = this.getAttribute(key);
+      }
 
       this._props[camelized] = convertAttributeValue(value, key, camelizedPropsMap[camelized]);