首页 > 解决方案 > 调整窗口大小时,svelte/sapper 中的 InvalidCharacterError

问题描述

我用工兵建立了一个网站。当我调整窗口大小(变小,然后又变大)时,我在 Firefox 中收到此错误:

String contains an invalid character in svelte

在文件index.mjs:249中。单击文件会导致此功能:

function attr(node, attribute, value) {
    if (value == null)
        node.removeAttribute(attribute);
    else if (node.getAttribute(attribute) !== value)
        node.setAttribute(attribute, value);
}

错误似乎就在这里:node.setAttribute(attribute, value); 有人知道可能导致此错误的原因吗?我有一些条件逻辑来根据窗口大小显示组件:

<script>
  let windowSize;
</script>

<svelte:window bind:innerWidth={windowSize} />

{#if windowSize >= 768}
  <Image />
{/if}

这会导致错误吗?

更新

谷歌浏览器抛出此错误:

Uncaught (in promise) DOMException: Failed to execute 'setAttribute' on 'Element': '`rel' is not a valid attribute name.

标签: javascriptsveltesapper

解决方案


解决它。标记的属性中有一个反引号 (`) <a />

<a
  `rel="noreferrer"
   aria-label={external}
   class="social-media-icon"
   target="_blank"
   href={external}>

推荐阅读