html - Is there any way to embed JavaScript into Vitepress markdown template? - Stack Overflow

Is there a way to embed a script from external source as well as local script into Vitepress markdown f

Is there a way to embed a script from external source as well as local script into Vitepress markdown for it to be generated?

This example

## my test button

<script src=";></script>
<script>
  function initButton() {
     ...
  }
</script>

throws up an issue

[vite] hmr update /test/index.md (x2) 19:00:17 [vite] Internal server error: Tags with side effect ( and ) are ignored in client ponent templates. Plugin: vite:vue

Is there a way to embed a script from external source as well as local script into Vitepress markdown for it to be generated?

This example

## my test button

<script src="https://www.jsdeliver./sdk/js?yadayada"></script>
<script>
  function initButton() {
     ...
  }
</script>

throws up an issue

[vite] hmr update /test/index.md (x2) 19:00:17 [vite] Internal server error: Tags with side effect ( and ) are ignored in client ponent templates. Plugin: vite:vue

Share Improve this question edited Feb 24, 2023 at 19:59 isherwood 61.2k16 gold badges121 silver badges170 bronze badges asked Jan 12, 2022 at 19:02 mirageglobemirageglobe 3,1542 gold badges32 silver badges31 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

a first possible way is through the config file (.vitepress/config.js) which is possible embed the scripts into the generated vitepress index.html. the documentation doesnt explain it well but this works if we need to place scripts into header.

the following is an example of google tag header script.

export default {
  title: 'mydocumentation',
  head: [
    [
      'script',
      {
        async: true,
        src: 'https://www.googletagmanager./gtag/js?id=G-xxxxxxxxx'
      }
    ],
    [
      'script',
      {},
      `
      window.dataLayer = window.dataLayer || [];
      ...

      gtag('config', 'G-xxxxxxxxxxx');
      `
    ]
  ]
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745109076a4611738.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信