Skip to content

Commit 1f34945

Browse files
committed
Change component declaration
1 parent 824422d commit 1f34945

File tree

2 files changed

+30
-56
lines changed

2 files changed

+30
-56
lines changed

docs/.vuepress/components/SFCButton.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default {
1616
methods: {
1717
handleClick() {
1818
this.count++;
19-
console.log('clicked');
19+
console.log('clicked', this.count);
2020
},
2121
},
2222
};

docs/patterns/README.md

+29-55
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,7 @@
99

1010
### [Single File Component (a.k.a. SFC)](https://vuejs.org/v2/guide/single-file-components.html) - Most Common
1111

12-
```vue
13-
<template>
14-
<p class="demo">
15-
<button class="btn-primary" @click.prevent="handleClick">
16-
<slot></slot>(clicked - {{count}})
17-
</button>
18-
</p>
19-
</template>
20-
21-
<script>
22-
export default {
23-
data() {
24-
return {
25-
count: 0,
26-
};
27-
},
28-
methods: {
29-
handleClick() {
30-
this.count++;
31-
console.log('clicked');
32-
},
33-
},
34-
};
35-
</script>
36-
37-
<style scoped>
38-
.btn-primary {
39-
display: inline-block;
40-
font-size: 1.2rem;
41-
color: #fff;
42-
background-color: #3eaf7c;
43-
padding: 0.8rem 1.6rem;
44-
border-radius: 4px;
45-
transition: background-color 0.1s ease;
46-
box-sizing: border-box;
47-
border-bottom: 1px solid #389d70;
48-
}
49-
</style>
50-
```
12+
<<< @/docs/.vuepress/components/SFCButton.vue
5113

5214
<SFCButton>SFC</SFCButton>
5315

@@ -57,7 +19,7 @@ export default {
5719
Vue.component('my-btn', {
5820
template: `
5921
<button class="btn-primary" @click.prevent="handleClick">
60-
{{text}}
22+
<slot></slot>(clicked - {{count}})
6123
</button>
6224
`,
6325
data() {
@@ -66,8 +28,16 @@ Vue.component('my-btn', {
6628
};
6729
},
6830
methods: {
69-
handleClick() {
70-
console.log('clicked');
31+
data() {
32+
return {
33+
count: 0,
34+
};
35+
},
36+
methods: {
37+
handleClick() {
38+
this.count++;
39+
console.log('clicked', this.count);
40+
},
7141
},
7242
},
7343
});
@@ -77,14 +47,17 @@ Vue.component('my-btn', {
7747

7848
```js
7949
Vue.component('my-btn', {
80-
data() {
81-
return {
82-
text: 'Click me',
83-
};
84-
},
8550
methods: {
86-
handleClick() {
87-
console.log('clicked');
51+
data() {
52+
return {
53+
count: 0,
54+
};
55+
},
56+
methods: {
57+
handleClick() {
58+
this.count++;
59+
console.log('clicked', this.count);
60+
},
8861
},
8962
},
9063
render(h) {
@@ -98,7 +71,7 @@ Vue.component('my-btn', {
9871
click: this.handleClick,
9972
},
10073
},
101-
this.text
74+
this.$slots.default
10275
);
10376
},
10477
});
@@ -120,8 +93,8 @@ Vue.component('my-btn', {
12093
},
12194
render() {
12295
return (
123-
<button class="btn-primary" onClick={this.handleClick}>
124-
{{this.text}}
96+
<button class="btn-primary" @click.prevent="handleClick">
97+
{this.$slots.default}(clicked - {{count}})
12598
</button>
12699
);
127100
},
@@ -133,7 +106,7 @@ Vue.component('my-btn', {
133106
```vue
134107
<template>
135108
<button class="btn-primary" @click.prevent="handleClick">
136-
{{text}}
109+
<slot></slot>(clicked - {{count}})
137110
</button>
138111
</template>
139112
@@ -143,10 +116,11 @@ import Component from 'vue-class-component';
143116
144117
@Component
145118
export default MyBtn extends Vue {
146-
text = 'Click me';
119+
count = 0;
147120
148121
handleClick() {
149-
console.log('clicked');
122+
this.count++;
123+
console.log('clicked', this.count);
150124
}
151125
}
152126
</script>

0 commit comments

Comments
 (0)