Skip to content

Commit 0aae0e3

Browse files
committed
fix: ssr compatibility
1 parent 549e251 commit 0aae0e3

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

src/index.spec.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,7 @@ export default tester(
5959
},
6060
},
6161
[
62-
testerPluginComponent({
63-
componentPath: require.resolve('./index.vue'),
64-
pluginMode: 'client',
65-
}),
62+
testerPluginComponent({ componentPath: require.resolve('./index.vue') }),
6663
testerPluginPuppeteer(),
6764
]
6865
)

src/index.vue

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
<script>
2-
import mermaid from 'mermaid'
3-
42
export default {
53
mounted() {
6-
mermaid.parseError = error => {
7-
console.log('this is a parse error')
8-
this.$emit('parse-error', error)
4+
if (typeof window !== 'undefined') {
5+
const mermaid = require('mermaid')
6+
mermaid.parseError = error => this.$emit('parse-error', error)
7+
mermaid.initialize({
8+
securityLevel: 'loose',
9+
startOnLoad: false,
10+
theme: 'default',
11+
})
12+
mermaid.init(this.value, this.$el)
913
}
10-
mermaid.initialize({
11-
securityLevel: 'loose',
12-
startOnLoad: false,
13-
theme: 'default',
14-
})
15-
mermaid.init(this.value, this.$el)
1614
},
1715
name: 'VueMermaidComponent',
1816
props: {

0 commit comments

Comments
 (0)