dewfall123 / vitepress-for-component

📖 针对组件开发的VitePress。 重构版本https://github.com/dewfall123/ruabick
https://dewfall123.github.io/vitepress-for-component/
MIT License
194 stars 38 forks source link

dev时,<demo>的渲染时机过早 #49

Closed zhangshichun closed 2 years ago

zhangshichun commented 2 years ago

Describe the bug dev 时,head中script还未完成加载,demo内组件的onMounted已经完成了执行

To Reproduce Steps to reproduce the behavior: 第一步:在 docs/public 下创建 test.js

window.TEST_FN = () => {
  console.log(123)
}

第二步:在 .md 文件中引入该script

---
head:
  - - script
    - src: '/test.js'
---

第三步:在demo或某个组件的onMounted里执行:

  window.TEST_FN()

Expected behavior 期望:可以成功打印 123

System Info

dewfall123 commented 2 years ago

可以这样引入script

// .vitepress\config.js
...
head: [['script', { src: '/test.js' }]],
...

参考 https://github.com/vuejs/vitepress/issues/375

zhangshichun commented 2 years ago

可以这样引入script

// .vitepress\config.js
...
head: [['script', { src: '/test.js' }]],
...

参考 vuejs/vitepress#375

thank u! 有效