Skip to content

Commit 280eb11

Browse files
committed
Add error boundary example
1 parent 116553c commit 280eb11

File tree

5 files changed

+79
-2
lines changed

5 files changed

+79
-2
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<script>
2+
export default {
3+
name: 'ErrorBoundary',
4+
data() {
5+
return {
6+
error: false,
7+
errorMessage: '',
8+
};
9+
},
10+
errorCaptured(err, vm, info) {
11+
this.error = true;
12+
this.errorMessage = `Sorry, error occured in ${info}`;
13+
14+
return false;
15+
},
16+
render(h) {
17+
if (this.error) {
18+
return h('p', { class: 'demo bg-danger' }, this.errorMessage);
19+
}
20+
21+
return this.$slots.default[0];
22+
},
23+
};
24+
</script>

docs/.vuepress/components/SFCButton.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default {
1919
console.log('clicked');
2020
},
2121
},
22-
}
22+
};
2323
</script>
2424

2525
<style scoped>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<template>
2+
<p class="demo">
3+
<button class="btn btn-danger" @click.prevent="throwError()">Error Thrown Button ({{count}})</button>
4+
</p>
5+
</template>
6+
7+
<script>
8+
export default {
9+
data() {
10+
return {
11+
count: 0,
12+
};
13+
},
14+
watch: {
15+
count() {
16+
throw new Error('error');
17+
},
18+
},
19+
methods: {
20+
throwError() {
21+
this.count++;
22+
},
23+
},
24+
};
25+
</script>

docs/.vuepress/override.styl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.btn {
2+
display: inline-block;
3+
font-size: 1.2rem;
4+
color: #212121;
5+
padding: 0.8rem 1.6rem;
6+
border-radius: 4px;
7+
transition: background-color 0.1s ease;
8+
box-sizing: border-box;
9+
}
10+
11+
.btn-primary {
12+
color: #fff;
13+
background-color: #3eaf7c;
14+
}
15+
16+
.btn-danger {
17+
color: #fff;
18+
background-color: #da5961;
19+
}
20+
21+
.bg-danger {
22+
color: #fff;
23+
background-color: #da5961;
24+
}

docs/patterns/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default {
3131
console.log('clicked');
3232
},
3333
},
34-
}
34+
};
3535
</script>
3636

3737
<style scoped>
@@ -962,6 +962,10 @@ export default {
962962
</error-boundary>
963963
```
964964

965+
<ErrorBoundary>
966+
<ThrowError></ThrowError>
967+
</ErrorBoundary>
968+
965969
#### Examples
966970

967971
- [Example 1](https://jsfiddle.net/Linusborg/z84wspcg/)

0 commit comments

Comments
 (0)