Skip to content

Commit cc4f736

Browse files
committed
组件化开发1
1 parent 51f8b15 commit cc4f736

31 files changed

+276
-65
lines changed

app.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,9 @@
22
"pages": [
33
"pages/home/home",
44
"pages/about/about"
5-
]
5+
],
6+
"usingComponents": {
7+
"my-cpn": "/components/my-cpn/my-cpn"
8+
},
9+
"sitemapLocation": "sitemap.json"
610
}

components/cpn1/cpn1.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// components/cpn1/cpn1.js
2+
Component({
3+
/**
4+
* 组件的属性列表
5+
*/
6+
properties: {
7+
8+
},
9+
10+
/**
11+
* 组件的初始数据
12+
*/
13+
data: {
14+
15+
},
16+
17+
/**
18+
* 组件的方法列表
19+
*/
20+
methods: {
21+
22+
}
23+
})

components/cpn1/cpn1.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"component": true,
3+
"usingComponents": {}
4+
}

components/cpn1/cpn1.wxml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<!--components/cpn1/cpn1.wxml-->
2+
<view class='box'>我是cpn1</view>

components/cpn1/cpn1.wxss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* components/cpn1/cpn1.wxss */
2+
.box {
3+
background: orange;
4+
}

components/my-cpn/my-cpn.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// components/my-cpn/my-cpn.js
2+
Component({
3+
/**
4+
* 组件的属性列表
5+
*/
6+
properties: {
7+
8+
},
9+
10+
/**
11+
* 组件的初始数据
12+
*/
13+
data: {
14+
title: '我是标题'
15+
},
16+
17+
/**
18+
* 组件的方法列表
19+
*/
20+
methods: {
21+
22+
}
23+
})

components/my-cpn/my-cpn.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"component": true,
3+
"usingComponents": {
4+
"cpn1": "/components/cpn1/cpn1"
5+
}
6+
}

components/my-cpn/my-cpn.wxml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!--components/my-cpn/my-cpn.wxml-->
2+
<view class='title'>{{title}}</view>
3+
<view class='content'>我是自定义组件的内容</view>
4+
<cpn1/>
5+

components/my-cpn/my-cpn.wxss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* components/my-cpn/my-cpn.wxss */
2+
.title {
3+
font-size: 40rpx;
4+
font-weight: 700;
5+
}
6+
7+
.content {
8+
font-size: 30rpx;
9+
}

components/my-event/my-event.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// components/my-event/my-event.js
2+
Component({
3+
methods: {
4+
handleIncrement() {
5+
// console.log('---------')
6+
this.triggerEvent('increment', {name: 'why', age: 18}, {})
7+
}
8+
}
9+
})

0 commit comments

Comments
 (0)