小编Арт*_*щев的帖子

如何代理自定义元素(Web组件)

class A extends HTMLElement {
  constructor() {
    super()
    return new Proxy(this, {})
  }
}

window.customElements.define('a-element', A)
Run Code Online (Sandbox Code Playgroud)
<a-element></a-element>
Run Code Online (Sandbox Code Playgroud)

我如何代理自定义元素?

当我尝试它:

Uncaught InvalidStateError: custom element constructors must call super() first and must not return a different object.

javascript web-component custom-element es6-proxy es6-class

14
推荐指数
1
解决办法
1034
查看次数

如何在&lt;script type =“ module”&gt;中获取document.currentScript.ownerDocument?

我如何在script type =“ module”中获得ownerDocument?

<template>
  text
</template>
<script type="module">
  let owner = document.currentScript.ownerDocument // is null
  
  // But i need get <template>
  
  let tpl = owner.querySelector('template')
</script>
Run Code Online (Sandbox Code Playgroud)

html web-component ecmascript-6 es6-modules

5
推荐指数
1
解决办法
723
查看次数