BuptStEve / vuepress-plugin-demo-code

📝 Demo and code plugin for vuepress
https://buptsteve.github.io/vuepress-plugin-demo-code/
MIT License
125 stars 28 forks source link

多data报错 #11

Closed any-u closed 5 years ago

any-u commented 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 将失效,并且报错。 我使用的时候是这个问题,然后拉取了源仓库,稍做修改,也有该问题。

所以,想问下有什么解决方案吗,谢谢!

any-u commented 5 years ago

打开vue-devtools 发现单个markdown文件是作为同一个组件,所以data会被后面的覆盖掉

BuptStEve commented 5 years ago

推荐使用 https://github.com/xiguaxigua/vuepress-plugin-demo-block

BuptStEve commented 5 years ago

暂时没别的办法,或者可以把多个实例写在一个里面。