You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+254Lines changed: 254 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -100,6 +100,260 @@ module.exports = {
100
100
};
101
101
```
102
102
103
+
## Events
104
+
105
+
### `@error`
106
+
107
+
When the template compilation or the script evaluation fail, errors are returned in this box. Hooking on these errors will not prevent them from displaying on the preview panel but will allow you to provide more info to your users about how to fix what they see.
108
+
109
+
```vue
110
+
<template>
111
+
<VueLive
112
+
code="<h1>make this example {{ fail }}</h1>"
113
+
@error="(e) => log('Error on first example', e)"
114
+
/>
115
+
</template>
116
+
```
117
+
118
+
## Props
119
+
120
+
### `code`
121
+
122
+
**Type** String
123
+
124
+
Specifies the initial code to be evaluated
125
+
126
+
```vue
127
+
<template>
128
+
<VueLive code="<button>test</button>" />
129
+
</template>
130
+
```
131
+
132
+
### `layout`
133
+
134
+
**Type** vue component
135
+
136
+
Layout to be used for displaying the
137
+
138
+
Example
139
+
140
+
```vue
141
+
<template>
142
+
<VueLive :layout="layout" />
143
+
</template>
144
+
<script>
145
+
import layout from "./Layout.vue";
146
+
147
+
export default {
148
+
data() {
149
+
return { layout };
150
+
},
151
+
};
152
+
</script>
153
+
```
154
+
155
+
`layout.vue`
156
+
157
+
```vue
158
+
<template>
159
+
<div class="my-vuelive">
160
+
<div class="my-vuelive-editor">
161
+
<slot name="editor"></slot>
162
+
</div>
163
+
<div class="my-vuelive-preview">
164
+
<slot name="preview"></slot>
165
+
</div>
166
+
</div>
167
+
</template>
168
+
<style>
169
+
.my-vuelive {
170
+
border: 1px solid #ccc;
171
+
border-radius: 10px;
172
+
}
173
+
174
+
.my-vuelive-editor {
175
+
margin: 8px;
176
+
}
177
+
178
+
.my-vuelive-preview {
179
+
margin: 8px;
180
+
}
181
+
</style>
182
+
```
183
+
184
+
### `components`
185
+
186
+
**Type** Object:
187
+
188
+
- key: registration name
189
+
- value: VueJs component object
190
+
191
+
Register some components to be used in the vue-live instance.
- value: value returned by an es5 reauire statement
220
+
221
+
To allow require statements on a code evaluated in the browser, we have to pre-package all dependencies. This allows bundlers to know in advance what external dependencies will be allowed in the code.
JSX does not always play nice with vue templates. If you want to expose vue templates, leave this option off. If you plan on using render functions with JSX, you will have to turn this option on.
262
+
263
+
Example
264
+
265
+
```vue
266
+
<template>
267
+
<vue-live :code="code" jsx />
268
+
</template>
269
+
<script>
270
+
export default {
271
+
data() {
272
+
return {
273
+
code: `
274
+
const args = {
275
+
type: "button",
276
+
value: "update me"
277
+
};
278
+
279
+
export default {
280
+
render() {
281
+
return <input {...args} />;
282
+
}
283
+
};
284
+
`,
285
+
};
286
+
},
287
+
};
288
+
</script>
289
+
```
290
+
291
+
### `delay`
292
+
293
+
**Type** Number
294
+
295
+
Time between a change in the code and its effect in the preview.
296
+
297
+
> **Note** If a change happens before the prview has changed, the timer is reset.
298
+
299
+
### `editorProps`
300
+
301
+
**Type** Object
302
+
303
+
Props passed directly to [vue-prism-editor](https://github.com/koca/vue-prism-editor) as a spread
304
+
305
+
### `dataScope`
306
+
307
+
**Type** Object
308
+
309
+
Data object that wil be merged with the output data of the preview.
310
+
311
+
Example
312
+
313
+
````vue
314
+
```vue
315
+
<template>
316
+
<VueLive
317
+
:components="registeredComponents"
318
+
:data-scope="dataScope"
319
+
code="<DatePicker :value='today' />{{ today }}"
320
+
/>
321
+
</template>
322
+
<script>
323
+
import DatePicker from "./DatePicker.vue";
324
+
325
+
export default {
326
+
data() {
327
+
return {
328
+
registeredComponents: {
329
+
DatePicker,
330
+
},
331
+
// Without this variable declaration,
332
+
// today will not have a value when entering the
333
+
// particularly useful when examples or only a template
334
+
dataScope: {
335
+
today: new Date(),
336
+
},
337
+
};
338
+
},
339
+
};
340
+
</script>
341
+
````
342
+
343
+
### `checkVariableAvailability`
344
+
345
+
**Type** Boolean
346
+
347
+
Makes sure that every variable in the template actually exists when the user starts editing.
348
+
349
+
Throws an error in te preview field when the variable dont exist.
350
+
351
+
### `squiggles`
352
+
353
+
**Type** Boolean default: `true`
354
+
355
+
Shows a red indicator when the parser errors with the code given.
0 commit comments