0

У меня есть example.html

<template id ="varan-nav">
<varan-nav>
    <nav role="navigation" id="navigation" class="navigation " style="height: 75.264px;">
        <a href="/about" class="item"></a>
        <a href="/material/1" class="item"></a>
        <a href="/services" class="item"></a>
        <a href="/price/" class="item"></a>
        <a href="/contacts" class="item"></a>
    </nav>
</varan-nav>
</template>

И есть web component

customElements.define('varan-nav',
    class extends HTMLElement {
        constructor () {
        white['varan-nav'] = super()
        white['varan-nav-shadowRoot'] = this.attachShadow({mode: 'open'})
        let parser = new DOMParser()
        let doc = parser.parseFromString(`dfgdfg`, 'text/html')
        }
    }
)

Я могу использовать DOMParser что бы записать строку, но не могу прочитать html.

Как я могу получить html <template>?

1 ответ 1

0
   fetch('/static/html/components/varan-header-footer/varan-header-footer.html').then(function (response) {
    return response.text()
  }).then(function (body) {
    let parser = new DOMParser()
    let doc = parser.parseFromString(body, 'text/html')
    let template = doc.getElementsByTagName('template')[0]
    white['varan-header-footer-shadowRoot'].appendChild(template.content.cloneNode(true))
  })

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.