SFC 完整样例
基础功能展示
入口组件 entry.aip 引用了 utils.ts 和 a.css
<!-- entry.aip -->
<template aip>
<aip-view [class]="[viewClass, className]" id="idB">
<aip-button
width="80"
class="classB classInA classNotDefined"
height="40"
aip-show="showBtn"
(click)="onClick"
>
<div id="idInA">Button</div>
</aip-button>
</aip-view>
</template>
<script>
import { afterInit, logOne } from './utils';
export default {
state: {
className: '',
viewClass: `classInA classB`,
name: 'defaultValue',
},
init() {
let a = 1;
this.$watch('name', newValue => {
console.log(newValue);
});
afterInit();
},
effect() {
console.log('effect');
},
methods: {
onClick() {
console.log(`props ${this.className}`);
console.log('click');
},
},
};
</script>
<style>
@import './a.css';
#idB {
line-height: 1.5;
}
.classB {
color: yellow;
}
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// utils.ts
let a: number;
export const afterInit = () => {
a = 2;
console.log(a);
};
export const logOne = () => {
console.log('one');
};
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
/* a.css */
.classInA {
background-color: #fff;
}
#idInA {
font-size: 12px;
}
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
调用方式 1: 生成模版片段
transformSFC('./entry.aip', { target: 'template' });
1
输出结果:
<aip-view
aip-state="(() => {var a;var afterInit = () => {a = 2;console.log(a);};return { className: 'customClass', viewClass: `classInA classB`, showBtn: false, name: 'defaultValue', onClick() {console.log(`props ${this.className}`);console.log('click');}, init() {let a2 = 1;$watch(name, (newValue) => {console.log(newValue);});afterInit();}, effect() {console.log('effect');} };})()"
style="line-height:1.5;"
[class]="[viewClass, className]"
id="idB"
aip-init="init()"
aip-effect="effect()"
>
<aip-button
class="classB classInA classNotDefined"
style="color:yellow;background-color:#fff;"
width="80"
height="40"
aip-show="showBtn"
(click)="onClick"
>
<div id="idInA">Button</div>
</aip-button>
</aip-view>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
调用方式 2: 生成 AIP html
transformSFC('./entry.aip', { target: 'html', title: 'AIP 落地页' });
1
输出结果:
<!DOCTYPE html>
<html aip>
<head>
<meta charset="utf-8" />
<title>AIP 落地页</title>
<meta
name="viewport"
content="width=device-width,minimum-scale=1,initial-scale=1"
/>
<link
rel="stylesheet"
type="text/css"
href="https://unpkg.byted-static.com/latest/byted-fangyuan/aip/dist/aip.css"
/>
<script
defer
src="https://unpkg.byted-static.com/latest/byted-fangyuan/aip/dist/aip.iife.js"
></script>
<script
defer
src="https://unpkg.byted-static.com/latest/byted-fangyuan/aip-ui/dist/aip-button/aip-button.iife.js"
></script>
<script
defer
src="https://unpkg.byted-static.com/latest/byted-fangyuan/aip-ui/dist/aip-swiper/aip-swiper.iife.js"
></script>
<script
defer
src="https://unpkg.byted-static.com/latest/byted-fangyuan/aip-ui/dist/aip-icon/aip-icon.iife.js"
></script>
<script
defer
src="https://unpkg.byted-static.com/latest/byted-fangyuan/aip-ui/dist/aip-rate/aip-rate.iife.js"
></script>
<script
defer
src="https://unpkg.byted-static.com/latest/byted-fangyuan/aip-ui/dist/aip-download/aip-download.iife.js"
></script>
<script
defer
src="https://unpkg.byted-static.com/latest/byted-fangyuan/aip-ui/dist/aip-form/aip-form.iife.js"
></script>
<script
defer
src="https://unpkg.byted-static.com/latest/byted-fangyuan/aip-ui/dist/aip-input/aip-input.iife.js"
></script>
<script
defer
src="https://unpkg.byted-static.com/latest/byted-fangyuan/aip-ui/dist/aip-byted-form/aip-byted-form.iife.js"
></script>
<script
defer
src="https://unpkg.byted-static.com/latest/byted-fangyuan/aip-ui/dist/aip-byted-video/aip-byted-video.iife.js"
></script>
<style aip-custom>
#idB {
line-height: 1.5;
}
.classB {
color: yellow;
}
.classInA {
background-color: #fff;
}
#idInA {
font-size: 12px;
}
</style>
</head>
<script>
window.__AIP_RESOURCES = {};
</script>
<body>
<aip-view
aip-state="(() => {var a;var afterInit = () => {a = 2;console.log(a);};return { className: 'customClass', viewClass: `classInA classB`, showBtn: false, name: 'defaultValue', onClick() {console.log(`props ${this.className}`);console.log('click');}, init() {let a2 = 1;$watch(name, (newValue) => {console.log(newValue);});afterInit();}, effect() {console.log('effect');} };})()"
[class]="[viewClass, className]"
id="idB"
aip-init="init()"
aip-effect="effect()"
>
<aip-button
class="classB classInA classNotDefined"
width="80"
height="40"
aip-show="showBtn"
(click)="onClick"
>
<div id="idInA">Button</div>
</aip-button>
</aip-view>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95