1. 设置状态栏的背景颜色
my.setNavigationBar : https://opendocs.alipay.com/mini/api/xwq8e6
2. 组件
注意:组件命名不能用驼峰形式 只能用 - 拼接
子组件:
.axml<view>......</view>.jsComponent({props:{test1:'文本1',onClickMe: () => {},},methods: {onClickMe() {this.props.onClickMe();},},});.json{"component": true}
父组件:
.json{"defaultTitle": "商家名称","usingComponents": {"shop-info":"./components/shop-info/index"}}.axml<shop-info/>
3.UI包
4.开发中注意的点
- props不可再子组件中修改,要通过函数在父组件中做修改
```css
父组件.axml
子组件.js Component({ data: { counter: 0 }, // 设置默认属性 props: { onCounterPlusOne: (data) => console.log(data), extra: ‘default extra’, }, methods: { plusOne(e) { console.log(e); const counter = this.data.counter + 1; this.setData({ counter }); this.props.onCounterPlusOne(counter); // axml中的事件只能由methods中的方法响应 }, }, });
<a name="bFGgc"></a>#### 5. slot插槽1. 默认插槽(只能有一个)```htmlfather.axml<child><view>i am default slot</view></child>child.axml<view><slot><view>i am child</view></slot></view>
- 具名插槽
```html
father.axml
i am slot1 i am slot2
child.axml
3. 具名插槽和默认插槽可以一起使用<a name="kBxF8"></a>#### 6. 接口请求```javascriptapi.jsconst API_HOST = 'http://aliisv.beihu.ltd/m.api';export function getUserInfo(authCode) {return new Promise((resolve, reject) => {try{const url = `${API_HOST}/alipay/demo/alipayUserInfo`;my.request({url,data: {authCode,},success: (res) => {if (!res.data.success) {reject(res);}resolve(res.data);},fail: (error) => {reject(error);}});}catch(error){reject(error)}});}page.jsimport {commenRequest} from '../../utils/api'async onLoad(){let sendData={}let res = await commenRequest({_gp,_mt:'',...sendData})this.setData({...})},
7. 页面跳转、传参、收参
//axml<view data-orderId="{{1}}" onTap="gotoPage"></view>//页面跳转gotoPage(e){my.navigateTo({url:`/pages/orderDetail/index?orderId=${e.target.dataset.orderId}&mark='pagemark'`,});}//收参onLoad(options){console.log(options) //{orderId:'1',mark:'pagemark'}}
