Let's take a look at the differences between Alipay mini program and WeChat mini program development

coldplay.xixi
Release: 2021-04-14 10:25:45
forward
3484 people have browsed it

Let's take a look at the differences between Alipay mini program and WeChat mini program development

A brief discussion on the difference between the development of Alipay mini programs and WeChat mini programs

1. app.json

(1) Set the status bar, navigation bar, title, and window background color common to the mini program

Alipay mini program

  "window": {
    "defaultTitle": "病案到家",   //页面标题
    "titleBarColor": "#1688FB"    //导航栏背景色
  },
Copy after login

WeChat Mini Program

  "window": {
    "backgroundTextStyle": "light",//窗口的背景色
    "navigationBarBackgroundColor": "#1688FB",//导航栏背景颜色
    "navigationBarTitleText": "病案到家",//导航栏标题文字内容
    "navigationBarTextStyle": "white"//导航栏标题颜色,仅支持 black/white
  },
Copy after login

Related learning recommendations: 小programDevelopmentTutorial

(2) Set tabBar

Alipay Mini Program

"tabBar": {
    "textColor": "#333333",//默认颜色
    "selectedColor": "#1688FB",//选中颜色
    "backgroundColor": "#ffffff",//背景色
    "items": [
      {
        "icon": "/images/indexGrey.png",
        "activeIcon": "/images/indexWhite.png",
        "pagePath": "pages/homeIndex/homeIndex",
        "name": "首页"
      },
      {
        "icon": "/images/personGrey.png",
        "activeIcon": "/images/personWhite.png",
        "pagePath": "pages/orderList/orderList",
        "name": "我的"
      }
    ]
  }
Copy after login

WeChat Mini Program

"tabBar": {
    "color": "#333333",
    "selectedColor": "#1688FB",
    "backgroundColor": "#ffffff",
    "borderStyle": "#e5e5e5",
    "list": [
      {
        "iconPath": "/images/indexGrey.png",
        "selectedIconPath": "/images/indexWhite.png",
        "pagePath": "pages/homeIndex/homeIndex",
        "text": "首页"
      },
      {
        "iconPath": "/images/personGrey.png",
        "selectedIconPath": "/images/personWhite.png",
        "pagePath": "pages/orderList/orderList",
        "text": "我的"
      }
    ]
  }
Copy after login

2. Pages

(1) File naming is different

Alipay Mini Program

##WeChat Mini Program

I created pages in the WeChat mini program and the Alipay mini program respectively. The difference is:

1. In the Alipay mini program The suffix of the view layer page file is "axml", and the suffix of the style file is "acss";

2. The suffix of the view layer page file in the WeChat applet is "wxml", and the suffix of the style file is "wxss".

(2) View layer page axml and wxml

1. Bubble events and non-bubble events

Alipay applet

onTap, catchTap

On event binding will not prevent bubbling events from bubbling upwards, while catch event binding can prevent bubbling events from bubbling upwards.

<button class="weui-btn" onTap="login" type="primary">登录</button>
Copy after login

WeChat Mini Program

bindtapcatchtouchstart

bindEvent binding will not prevent bubbling events from bubbling upwards. catchEvent binding can prevent bubbling events from bubbling upwards.

<button class="weui-btn" bindtap=&#39;login&#39; type="primary">登录</button>
Copy after login

2. List rendering

Page({
  data: {
    list: [{
      Title: &#39;支付宝&#39;,
    }, {
      Title: &#39;微信&#39;,
    }]
  }
})
Copy after login

Alipay applet

<block a:for="{{list}}">
  <view key="item-{{index}}" index="{{index}}">{{item.Title}}</view>
</block>
Copy after login

WeChat applet

<block wx:for="{{list}}">
  <view wx:key="this" wx:for-item="item">{{item.Title}}</view>
</block>
Copy after login

3. Conditional rendering

Alipay applet

<view a:if="{{length > 5}}"> 1 </view>
<view a:elif="{{length > 2}}"> 2 </view>
<view a:else> 3 </view>
Copy after login

WeChat Mini Program

<view wx:if="{{length > 5}}"> 1 </view>
<view wx:elif="{{length > 2}}"> 2 </view>
<view wx:else> 3 </view>
Copy after login

3.Different usage of components in the two mini programs commonly used in the development process

(1) Interaction

1. Message prompt box

Alipay applet

my.showToast({
  type: &#39;success&#39;,//默认 none,支持 success / fail / exception / none’。
  content: &#39;操作成功&#39;,//文字内容
  duration: 3000,//显示时长,单位为 ms,默认 2000
  success: () => {
    my.alert({
      title: &#39;toast 消失了&#39;,
    });
  },
});
Copy after login
my.hideToast()//隐藏弱提示。
Copy after login

WeChat Mini Program

wx.showToast({
  title: &#39;成功&#39;,//提示的内容
  icon: &#39;success&#39;,//success	显示成功图标;loading	显示加载图标;none不显示图标
  duration: 2000
})

//icon为“success”“loading”时 title 文本最多显示 7 个汉字长度
Copy after login
rrree

2. Message prompt box

Alipay Mini Program

wx.hideToast() //隐藏
Copy after login
my.showLoading({
  content: &#39;加载中...&#39;,
  delay: 1000,
});
Copy after login

WeChat Mini Program

my.hideLoading();
Copy after login
wx.showLoading({
  title: &#39;加载中&#39;,
})
Copy after login

3.http request

Alipay Mini Program

wx.hideLoading()
Copy after login

WeChat Mini Program

my.httpRequest({
  url: &#39;http://httpbin.org/post&#39;,
  method: &#39;POST&#39;,
  data: {
    from: &#39;支付宝&#39;,
    production: &#39;AlipayJSAPI&#39;,
  },
  headers:"",//默认 {&#39;Content-Type&#39;: &#39;application/x-www-form-urlencoded&#39;}
  dataType: &#39;json&#39;,
  success: function(res) {
    my.alert({content: &#39;success&#39;});
  },
  fail: function(res) {
    my.alert({content: &#39;fail&#39;});
  },
  complete: function(res) {
    my.hideLoading();
    my.alert({content: &#39;complete&#39;});
  }
});
Copy after login

In fact, the API methods provided by WeChat Mini Program and Alipay Mini Program are roughly the same The same, except that the WeChat applet starts with "wx." and the Alipay applet starts with "my.". The rest may be just that the fields "text, content, name, title" in the API method are named differently.

(2) Selector

1. Time selector

Alipay applet

The Alipay applet provides an API, my.datePicker(object)

wx.request({
  url: &#39;test.php&#39;, //仅为示例,并非真实的接口地址
  data: {
    x: &#39;&#39;,
    y: &#39;&#39;
  },
  header: {
    &#39;content-type&#39;: &#39;application/json&#39; // 默认值
  },
  success (res) {
    console.log(res.data)
  }
})
Copy after login

WeChat applet

WeChat applet It is implemented through the picker component

my.datePicker({
  format: &#39;yyyy-MM-dd&#39;,//返回的日期格式,
  currentDate: &#39;2012-12-12&#39;,//初始选择的日期时间,默认当前时间
  startDate: &#39;2012-12-10&#39;,//最小日期时间
  endDate: &#39;2012-12-15&#39;,//最大日期时间
  success: (res) => {
    my.alert({
	  content: res.date,
	});
  },
});
Copy after login
<view class="section">
  <view class="section__title">日期选择器</view>
  <picker mode="date" value="{{date}}" start="2015-09-01" end="2017-09-01" bindchange="bindDateChange">
    <view class="picker">
      当前选择: {{date}}
    </view>
  </picker>
</view
Copy after login

2. Province and city selector

Alipay applet

Alipay applet The program provides an API, my.multiLevelSelect(Object)

The cascade selection function is mainly used for multi-level associated data selection, such as province and city information selection.

1.1. Introduce a json format file of a province or city http://blog.shzhaoqi.com/uploads/js/city_json.zip

1.2. Introduce this file in js

1.3. Use my.multiLevelSelect(Object)

Page({
  data: {
    date: &#39;2016-09-01&#39;,
  },

  bindDateChange: function(e) {
    console.log(&#39;picker发送选择改变,携带值为&#39;, e.detail.value)
    this.setData({
      date: e.detail.value
    })
  },
})
Copy after login

WeChat Mini Program

WeChat Mini Program still uses the picker component Implemented

var citysJSON = require(&#39;../../utils/city.js&#39;);
Page({
  data: {
    provinces: &#39;陕西省&#39;,
    city: &#39;西安市&#39;,
    area: &#39;碑林区&#39;
  },
  chooseAddress: function () {
    my.multiLevelSelect({
      title: &#39;选择省市区&#39;,//级联选择标题
      list: citysJSON.citys,
      success: (res) => {
        this.setData({
          provinces: res.result[0].name,
          city: res.result[1].name,
          area: res.result[2].name,
        })
      }
    });
  },
})
Copy after login
<view class="section">
  <view class="section__title">省市区选择器</view>
  <picker mode="region" bindchange="bindRegionChange" value="{{region}}" custom-item="{{customItem}}">
    <view class="picker">
      当前选择:{{region[0]}},{{region[1]}},{{region[2]}}
    </view>
  </picker>
</view>

//custom-item   可为每一列的顶部添加一个自定义的项,可为空
Copy after login

(3) Mini program evokes payment

Alipay mini program

Page({
  data: {
    region: [&#39;广东省&#39;, &#39;广州市&#39;, &#39;海珠区&#39;],
    customItem: &#39;全部&#39;
  },

  bindRegionChange: function (e) {
    console.log(&#39;picker发送选择改变,携带值为&#39;, e.detail.value)
    this.setData({
      region: e.detail.value
    })
  }
})
Copy after login

WeChat Mini Program

my.tradePay({
  tradeNO: &#39;201711152100110410533667792&#39;, // 调用统一收单交易创建接口(alipay.trade.create),获得返回字段支付宝交易号trade_no
  success: (res) => {
    my.alert({
	  content: JSON.stringify(res),
	});
  },
  fail: (res) => {
    my.alert({
	  content: JSON.stringify(res),
	});
  }
});
Copy after login

(4) Phone

支付宝小程序

my.makePhoneCall({
	number: &#39;400-8097-114&#39;
})
Copy after login

微信小程序

wx.makePhoneCall({
  phoneNumber: &#39;400-8097-114&#39;
})
Copy after login

(5)获取登录凭证(code)

支付宝小程序

my.getAuthCode({
  success (res) {
    if (res.authCode) {
      console.log(res.authCode)
    } 
  }
})
Copy after login

微信小程序

wx.login({
  success (res) {
    if (res.code) {
      console.log(res.code)
    } 
  }
})
Copy after login

支付宝小程序与微信小程序有很多相似之处,不论是组件还是api都会给你熟悉的感觉!

相关免费学习推荐:微信小程序开发

The above is the detailed content of Let's take a look at the differences between Alipay mini program and WeChat mini program development. For more information, please follow other related articles on the PHP Chinese website!

source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template