Closed any-u closed 5 years ago
同一个Markdown文件使用多次demo,而每次demo都拥有data, 类似于这种
// README.md ::: demo <template> {{a}} </template> <script> export default { data() { return { a: 1 } } } </script> ::: // -------------------------- ::: demo <template> {{b}} </template> <script> export default { data() { return { b: 1 } } } </script> :::
在这种情况下,第一个data 将失效,并且报错。 我使用的时候是这个问题,然后拉取了源仓库,稍做修改,也有该问题。
所以,想问下有什么解决方案吗,谢谢!
打开vue-devtools 发现单个markdown文件是作为同一个组件,所以data会被后面的覆盖掉
推荐使用 https://github.com/xiguaxigua/vuepress-plugin-demo-block
暂时没别的办法,或者可以把多个实例写在一个里面。
如何复现
同一个Markdown文件使用多次demo,而每次demo都拥有data, 类似于这种
在这种情况下,第一个data 将失效,并且报错。 我使用的时候是这个问题,然后拉取了源仓库,稍做修改,也有该问题。
所以,想问下有什么解决方案吗,谢谢!