Skip to content

Commit 3350b11

Browse files
committed
Refactor provide / inject
1 parent 1f34945 commit 3350b11

File tree

1 file changed

+10
-99
lines changed

1 file changed

+10
-99
lines changed

docs/patterns/README.md

+10-99
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ Notice that `<template>` element is not actually rendered into DOM. It is an inv
248248
</template>
249249
```
250250

251-
### JSX
251+
### Render Function or JSX
252252

253-
If you use JSX in your vue application, you can apply all the techniques such as `if else` and `switch case` statement and `ternary` and `logical` operator.
253+
If you use render function or JSX in your vue application, you can apply all the techniques such as `if else` and `switch case` statement and `ternary` and `logical` operator.
254254

255255
`if else` statement
256256

@@ -849,53 +849,12 @@ With above example component hierarchy, in order to derive data from `parent-com
849849
You can also use [vue-property-decorator](https://github.com/kaorun343/vue-property-decorator)'s `@Provide`, `@Inject`
850850
:::
851851

852-
```js
853-
// ThemeProvider
852+
#### ThemeProvider.vue
854853

855-
export default {
856-
provide: {
857-
theme: {
858-
primaryColor: '#3eaf7c',
859-
secondaryColor: '#1FA2FF'
860-
},
861-
},
862-
render(h) {
863-
return this.$slots.default[0];
864-
},
865-
};
866-
```
867-
868-
```vue
869-
// ThemeButton.vue
870-
871-
<template>
872-
<p class="demo">
873-
<button class="btn" :style="{ color: '#fff', backgroundColor: (primary && theme.primaryColor) || (secondary && theme.secondaryColor) }">
874-
<slot></slot>
875-
</button>
876-
</p>
877-
</template>
854+
<<< @/docs/.vuepress/components/ThemeProvider.vue
878855

879-
<script>
880-
export default {
881-
inject: {
882-
theme: {
883-
default: {},
884-
},
885-
},
886-
props: {
887-
primary: {
888-
type: Boolean,
889-
default: false,
890-
},
891-
secondary: {
892-
type: Boolean,
893-
default: false,
894-
},
895-
},
896-
};
897-
</script>
898-
```
856+
#### ThemeButton.vue
857+
<<< @/docs/.vuepress/components/ThemeButton.vue
899858

900859
```vue
901860
<theme-provider>
@@ -913,61 +872,13 @@ export default {
913872

914873
### `errorCaptured` Hook
915874

916-
```js
917-
// ErrorBoundary.vue
918-
export default {
919-
name: 'ErrorBoundary',
920-
data() {
921-
return {
922-
error: false,
923-
errorMessage: '',
924-
};
925-
},
926-
errorCaptured(err, vm, info) {
927-
this.error = true;
928-
this.errorMessage = `Sorry, error occured in ${info}`;
929-
930-
return false;
931-
},
932-
render(h) {
933-
if (this.error) {
934-
return h('p', { class: 'demo bg-danger' }, this.errorMessage);
935-
}
875+
#### ErrorBoundary.vue
936876

937-
return this.$slots.default[0];
938-
},
939-
};
940-
```
941-
942-
```vue
943-
// ThrowError.vue
877+
<<< @/docs/.vuepress/components/ErrorBoundary.vue
944878

945-
<template>
946-
<p class="demo">
947-
<button class="btn btn-danger" @click.prevent="throwError()">Error Thrown Button ({{count}})</button>
948-
</p>
949-
</template>
879+
#### ThrowError.vue
950880

951-
<script>
952-
export default {
953-
data() {
954-
return {
955-
count: 0,
956-
};
957-
},
958-
watch: {
959-
count() {
960-
throw new Error('error');
961-
},
962-
},
963-
methods: {
964-
throwError() {
965-
this.count++;
966-
},
967-
},
968-
};
969-
</script>
970-
```
881+
<<< @/docs/.vuepress/components/ThrowError.vue
971882

972883
```vue
973884
<error-boundary>

0 commit comments

Comments
 (0)