File tree 4 files changed +45
-6
lines changed 4 files changed +45
-6
lines changed Original file line number Diff line number Diff line change @@ -36,9 +36,11 @@ export default class ZButton extends tsc.Component<ButtonProps> {
36
36
}
37
37
38
38
@api ( demoApi )
39
- protected getResult ( res ?: string ) {
39
+ protected getResult ( ) {
40
40
// 获取api调用结果
41
- console . log ( res ) ;
41
+ return ( res ?: string ) => {
42
+ console . log ( res ) ;
43
+ } ;
42
44
}
43
45
44
46
protected render ( ) {
@@ -49,6 +51,8 @@ export default class ZButton extends tsc.Component<ButtonProps> {
49
51
return (
50
52
< div >
51
53
< p class = { className } > user: { this . user . name } </ p >
54
+ { this . $slots . default || "组件默认slot内容" }
55
+ { this . $slots . com_name_slot || "组件中的具名slot" }
52
56
< van-button type = { this . type } onClick = { ( ) => this . getResult ( ) } >
53
57
{ this . text || "我是按钮" }
54
58
</ van-button >
Original file line number Diff line number Diff line change 2
2
* @Author : ZhengXiaowei
3
3
* @Date : 2020-02-25 17:34:04
4
4
* @LastEditors : ZhengXiaowei
5
- * @LastEditTime : 2020-02-25 19:37:38
5
+ * @LastEditTime : 2020-03-05 09:42:51
6
6
* @Description : 自定义装饰器方法
7
7
* @FilePath : /src/decorator/index.ts
8
8
*/
@@ -19,9 +19,9 @@ export const api = (promise: Function) => {
19
19
descriptor . value = async function ( ) {
20
20
try {
21
21
let result = await promise ( ) ;
22
- oldValue . call ( this , result ) ;
22
+ oldValue . call ( this , ... arguments ) ( result ) ;
23
23
} catch ( e ) {
24
- oldValue . call ( this , { } , e ) ;
24
+ oldValue . call ( this , ... arguments ) ( { } , e ) ;
25
25
}
26
26
} ;
27
27
} ;
Original file line number Diff line number Diff line change
1
+ import * as tsx from "vue-tsx-support" ;
2
+
3
+ interface Props {
4
+ msg ?: string ;
5
+ name ?: string ;
6
+ }
7
+
8
+ export default tsx . componentFactory . create < Props , { } > ( {
9
+ name : "FunLayout" ,
10
+ functional : true ,
11
+ render ( h , ctx ) {
12
+ return (
13
+ < div >
14
+ { ctx . props . msg } - { ctx . props . name }
15
+ { ctx . slots ( ) . default }
16
+ { ctx . slots ( ) . name_slot || "默认的具名slot内容" }
17
+ </ div >
18
+ ) ;
19
+ }
20
+ } ) ;
Original file line number Diff line number Diff line change @@ -2,10 +2,25 @@ import { Component, Vue } from "vue-property-decorator";
2
2
import { Component as tsc } from "vue-tsx-support" ;
3
3
4
4
import ZButton , { BType } from "@/components/Button/Button" ;
5
+ import FunLayout from "@/fun-components/fun-layout" ;
5
6
6
7
@Component
7
8
export default class HomeContainer extends tsc < Vue > {
8
9
protected render ( ) {
9
- return < ZButton type = { BType . primary } > </ ZButton > ;
10
+ return (
11
+ < div >
12
+ < ZButton type = { BType . primary } >
13
+ < p > 替换组件默认slot</ p >
14
+ < p > 替换组件默认slot</ p >
15
+ < p > 替换组件默认slot</ p >
16
+ < p > 替换组件默认slot</ p >
17
+ < p slot = "com_name_slot" > 替换组件的具名slot</ p >
18
+ </ ZButton >
19
+ < FunLayout msg = "内容" name = "张三" >
20
+ < p > 默认的slot</ p >
21
+ < p slot = "name_slot" > 具名slot</ p >
22
+ </ FunLayout >
23
+ </ div >
24
+ ) ;
10
25
}
11
26
}
You can’t perform that action at this time.
0 commit comments