Skip to content

Commit e4f6a3e

Browse files
author
zhongjie
committed
将组件改造成ts
1 parent 00c7725 commit e4f6a3e

File tree

3 files changed

+84
-63
lines changed

3 files changed

+84
-63
lines changed

src/components/api-table.vue

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,24 +122,39 @@
122122
</div>
123123
</template>
124124

125-
<script>
125+
<script lang="ts">
126+
import Vue from 'vue';
127+
import { Component, Prop } from 'vue-property-decorator';
128+
126129
const dataApiThead = ['data属性', '说明', '类型', '固定值'];
127130
const attrThead = ['属性名', '说明', '类型', '默认值', '可选值', 'data属性'];
128131
const eventThead = ['事件名', '说明', '回调函数', '回调函数参数说明'];
129132
const hookThead = ['钩子名', '说明', '回调函数', '回调函数参数说明'];
130133
131-
export default {
132-
props: ['code', 'dataApiData', 'attrData', 'eventData', 'hookData'],
133-
data() {
134-
return {
135-
dataApiThead,
136-
attrThead,
137-
eventThead,
138-
hookThead
139-
}
140-
},
134+
@Component
135+
export default class extends Vue {
136+
dataApiThead: any[] = dataApiThead;
137+
attrThead: any[] = attrThead;
138+
eventThead: any[] = eventThead;
139+
hookThead: any[] = hookThead;
140+
141+
@Prop()
142+
code: any;
143+
144+
@Prop()
145+
dataApiData: any[];
146+
147+
@Prop()
148+
attrData: any[];
149+
150+
@Prop()
151+
eventData: any[];
152+
153+
@Prop()
154+
hookData: any[];
155+
141156
created() {
142-
cd.tooltip();
157+
(<any>window).cd.tooltip();
143158
}
144159
}
145160
</script>

src/components/panel.vue

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,39 @@
2020
</div>
2121
</template>
2222

23-
<script>
23+
<script lang="ts">
24+
import Vue from 'vue';
25+
import { Component, Prop } from 'vue-property-decorator';
2426
import Clipboard from 'clipboard';
2527
26-
export default {
27-
props: ['code'],
28-
data() {
29-
return {
30-
isShowCode: false
31-
}
32-
},
33-
methods: {
34-
toggleCode() {
35-
this.isShowCode = !this.isShowCode;
36-
},
37-
copy() {
38-
const clipboard = new Clipboard('.js-copy-code');
39-
clipboard.on('success', function(e) {
40-
cd.message({
41-
type: 'success',
42-
message: '复制成功'
43-
});
28+
@Component
29+
export default class extends Vue {
30+
isShowCode: boolean = false;
31+
32+
@Prop()
33+
code: any[];
4434
45-
clipboard.destroy();
46-
})
47-
}
48-
},
4935
created() {
50-
cd.tooltip({
36+
(<any>window).cd.tooltip({
5137
el: '.js-code-tooltip'
5238
});
5339
}
40+
41+
toggleCode() {
42+
this.isShowCode = !this.isShowCode;
43+
}
44+
45+
copy() {
46+
const clipboard = new Clipboard('.js-copy-code');
47+
clipboard.on('success', function(e) {
48+
(<any>window).cd.message({
49+
type: 'success',
50+
message: '复制成功'
51+
});
52+
53+
clipboard.destroy();
54+
})
55+
}
5456
}
5557
</script>
5658

src/components/theme-picker.vue

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
</div>
1212
</template>
1313

14-
<script>
14+
<script lang="ts">
15+
import Vue from 'vue';
16+
import { Component } from 'vue-property-decorator';
17+
1518
import { Sketch } from 'vue-color';
1619
1720
const defaultColor = {
@@ -24,35 +27,36 @@ const defaultColor = {
2427
}
2528
};
2629
27-
export default {
30+
@Component({
2831
components: {
2932
'sketch-picker': Sketch
30-
},
31-
data() {
32-
return {
33-
color: window.color || defaultColor,
34-
newColor: {},
35-
isShow: false
36-
}
37-
},
38-
methods: {
39-
select() {
40-
this.isShow = !this.isShow;
41-
},
42-
cancel() {
43-
this.isShow = false;
44-
},
45-
ok() {
46-
this.isShow = false;
33+
}
34+
})
35+
export default class extends Vue {
36+
37+
color: any = (<any>window).color || defaultColor;
38+
newColor: any = {};
39+
isShow: boolean = false;
40+
41+
select() {
42+
this.isShow = !this.isShow;
43+
}
44+
45+
cancel() {
46+
this.isShow = false;
47+
}
48+
49+
ok() {
50+
this.isShow = false;
51+
52+
this.$emit('ok', this.color, this.newColor);
53+
this.color = this.newColor;
54+
(<any>window).color = this.newColor;
55+
}
4756
48-
this.$emit('ok', this.color, this.newColor);
49-
this.color = this.newColor;
50-
window.color = this.newColor;
51-
},
52-
updateValue(color) {
53-
this.newColor = color;
54-
console.log(color, 'updateValue');
55-
},
57+
updateValue(color) {
58+
this.newColor = color;
59+
console.log(color, 'updateValue');
5660
}
5761
}
5862
</script>

0 commit comments

Comments
 (0)