# public
**Repository Path**: hackhu/public
## Basic Information
- **Project Name**: public
- **Description**: 公共模块,封装组件
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 3
- **Created**: 2019-11-25
- **Last Updated**: 2020-12-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# public
公共模块,封装组件
**
**小程序组件**
在需要用的页面的json文件中写下
```
"usingComponents":{
//"组件名": "路径" 列如
"button-list": "../../../mini-program-components/button-list/button-list"
}
```
:smirk: **1、button-list 模拟iOS列表组件**
页面中引用
```
//wxml
号 传任意值隐藏
>
//js
//如果使用循环
listArr:[
{
name:'我的会员卡',
img:'../../utils/img/my_01@3x.png'
},
{
name:'联系客服',
img:'../../utils/img/my_02@3x.png'
}]
buttonClick:(e) => {
//点击事件点击之后 e.detail.type == 传入组件的text值
console.log(e.detail.type);
switch (e.detail.type){
case '我的会员卡':
//...
break;
//....
}
```
:smirk: **2、city-picker 城市三级联动 选择组件**
页面中引用
```
//app.js
//判断本地是否有数据 没有 就请求
onLaunch:() => {
if (!wx.getStorageSync('citys')) {
wx.request({
url: "http://restapi.amap.com/v3/config/district?&subdistrict=3&key=你的高德key",
method: "GET",
success: function (res) {
console.log(res['data']['districts'][0]['districts']);
// 请求到数据 存在本地
wx.setStorageSync('citys', res['data']['districts'][0]['districts']);
}
})
}
}
//页面中
//wxml
//绑定选中事件
//js
selectCity: function(e){
console.log(e.detail);
//打印出来效果{province: "广西壮族自治区", city: "北海市", county: "合浦县"}
}
```