Skip to content

Commit 25fc627

Browse files
authored
feat: added prop dataScope for use outside data to the preview (#32)
1 parent e9d396d commit 25fc627

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/Preview.vue

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ export default {
4949
jsx: {
5050
type: Boolean,
5151
default: false
52+
},
53+
/**
54+
* Outside data to the preview
55+
* @example { count: 1 }
56+
*/
57+
dataScope: {
58+
type: Object,
59+
default: () => {}
5260
}
5361
},
5462
data() {
@@ -109,6 +117,11 @@ export default {
109117
adaptCreateElement,
110118
concatenate
111119
) || {};
120+
121+
if (this.dataScope) {
122+
const mergeData = { ...data.data(), ...this.dataScope };
123+
data.data = () => mergeData;
124+
}
112125
}
113126
if (renderedComponent.template) {
114127
// if this is a pure template or if we are in hybrid vsg mode,

src/VueLive.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
:language="lang"
77
:prismLang="prismLang"
88
:requires="requires"
9+
:data-scope="dataScope"
910
:components="components"
1011
>
1112
<template v-slot:editor>
@@ -25,6 +26,7 @@
2526
:components="components"
2627
:requires="requires"
2728
:jsx="jsx"
29+
:data-scope="dataScope"
2830
/>
2931
</template>
3032
</component>
@@ -110,6 +112,14 @@ export default {
110112
editorProps: {
111113
type: Object,
112114
default: () => ({})
115+
},
116+
/**
117+
* Outside data to the preview
118+
* @example { count: 1 }
119+
*/
120+
dataScope: {
121+
type: Object,
122+
default: () => {}
113123
}
114124
},
115125
data() {

0 commit comments

Comments
 (0)