Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,19 @@ When the template compilation or the script evaluation fail, errors are returned
</template>
```

### `@success`

When the template compilation and the script evaluation succeed, the `@success` event is emitted. If you provided extra info to your user about previous errors, you can use this event to clear the error message.

```vue
<template>
<VueLive
:code="code"
@success="error = undefined"
/>
</template>
```

## Props

### `code`
Expand Down
8 changes: 6 additions & 2 deletions src/Preview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ export default {
* @event
* @property { Error } - the error thrown
*/
this.$emit("error", e);
if (e.constructor === VueLiveParseTemplateError) {
e.message = `Cannot parse template expression: ${JSON.stringify(
e.expression.content || e.expression
)}\n\n${e.message}`;
}
this.$emit("error", e);
this.error = e.message;
},
renderComponent(code) {
Expand All @@ -125,7 +125,11 @@ export default {
const renderedComponent = compileScript(
code,
this.jsx
? { jsx: "__pragma__(h)", objectAssign: "__concatenate__", transforms: {asyncAwait: false} }
? {
jsx: "__pragma__(h)",
objectAssign: "__concatenate__",
transforms: { asyncAwait: false },
}
: { transforms: { asyncAwait: false } }
);
style = renderedComponent.style;
Expand Down
8 changes: 6 additions & 2 deletions src/VueLive.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
v-bind="layoutProps"
:code="stableCode"
:language="lang"
:prismLang="prismLang"
:prism-lang="prismLang"
:requires="requires"
:data-scope="dataScope"
:components="components"
Expand Down Expand Up @@ -33,7 +33,7 @@
:code="model"
@detect-language="switchLanguage"
@error="handleError"
@success="error = undefined"
@success="handleSuccess"
:components="components"
:requires="requires"
:jsx="jsx"
Expand Down Expand Up @@ -191,6 +191,10 @@ export default {
this.stableCode = this.model;
}
},
handleSuccess() {
this.error = undefined;
this.$emit("success");
},
handleError(e) {
this.error = e;
this.$emit("error", e);
Expand Down