微信小程序转为支付宝小程序注意点

微信小程序转为支付宝小程序

最近在做一个项目,需要将微信小程序转为支付宝小程序,因为第一次弄支付宝,现在将项目中遇到的一些问题、注意点总结一下

1:文件名修改

wxml改为axml
wxss改为acss

2调用api

js中调用方法由wx.改为my.
wx.request() => my. request()
axam中的循环、if判断等有wx:改为a:
wx:if => a:if
wx:for => a:for
wx:key => a:key
wx:for-item => a:for-item
wx:for-index => a:for-index

3html中调用方法

微信将调用方法写在.wxs文件中

var phone = function(val) {
    return val.substring(0, 4) + "*****" + val.substring(7, val.length);
   }
  module.exports = {
      phone:phone,
    }

wxml文件中导入对应方法

<wxs src="/wxs/substr.wxs" module="tools" />
        <text style="margin-right:10px;">{{tools.phone (comments.records[0].pjone)}}</text>

支付宝将调用方法写在.sjs文件中

var display = function (val) {
  return val ? (val.substring(0, 1) + "**") : '';
}
export default {
display:display,
}

axml文件中导入对应方法

<import-sjs from="/sjs/tools.sjs" name="tools"></import-sjs>
            <view class="row-title">{{tools.sub(option3[arrIndex1].text)}}</view>

4组件转换

微信小程序中常用的组件是vant组件,支付宝可以使用vant-aliapp组件(加载依赖),并在对应的json文件中加入

 "usingComponents": {
    "van-tabs": "vant-aliapp/dist/dist/tabs/index",
    "van-tab": "vant-aliapp/dist/dist/tab/index",
    "van-button": "vant-aliapp/dist/dist/button/index",
    "van-empty": "vant-aliapp/dist/dist/empty/index",
    "am-tabs": "mini-ali-ui/es/tabs/index",
    "tab-content": "mini-ali-ui/es/tabs/tab-content/index"
  }

注:并不是所有组件转换后都好用,类似于 van-dropdown-menu等组件vant-aliapp组件不能很好适应,可以使用mini-ali-ui组件(支付宝专用)进行组件替换

5绑定事件

微信支付宝
bindchangeonChange
bindtaponTap

6数据请求

微信中wx.request()请求数据时
header:{
headerToken : {},//对应toke
“content-type”: “application/json”//参数格式
},
在支付宝中my…request()请求数据时
headers:{
headerToken : {},//对应token
“content-type”: “application/json”//参数格式
},

7JS文件中具体api的变化

微信支付宝作用
wx.showModal()my.confirm()提示框

7page.json中差异

微信

"window": {
    "navigationBarTitleText": "互联网医院",
    "navigationBarBackgroundColor": "#fff",
    "navigationBarTextStyle": "black",
    "backgroundColor": "#eeeeee"
  },
  "tabBar": {
    "selectedColor": "#0068B7",
    "borderStyle": "white",
    "list": [
      {
        "pagePath": "pages/index/index",
        "iconPath": "images/tab_home.png",
        "selectedIconPath": "images/tab_home_s.png",
        "text": "首页"
      },
      {
        "pagePath": "pages/infomation/infomation",
        "iconPath": "images/tab_infomation.png",
        "selectedIconPath": "images/tab_infomation_s.png",
        "text": "资讯"
      },
      {
        "pagePath": "pages/me/me",
        "iconPath": "images/tab_me.png",
        "selectedIconPath": "images/tab_me_s.png",
        "text": "我的"
      }
    ]
  },

支付宝中

"window": {
    "defaultTitle": "互联网医院",
    "enableWK": "YES",
    "allowsBounceVertical": "YES"
  },
  "tabBar": {
    "textColor": "#404040",
    "selectedColor": "#108ee9",
    "backgroundColor": "#F5F5F9",
    "items": [
      {
        "pagePath": "pages/index/index",
        "icon": "images/tab_home.png",
        "activeIcon": "images/tab_home_s.png",
        "name": "首页"
      },
      {
        "pagePath": "pages/infomation/infomation",
        "icon": "images/tab_infomation.png",
        "activeIcon": "images/tab_infomation_s.png",
        "name": "资讯"
      },
      {
        "pagePath": "pages/me/me",
        "icon": "images/tab_me.png",
        "activeIcon": "images/tab_me_s.png",
        "name": "我的"
      }
    ]
  }

8其他功能示例链接

支付宝上传图片(示例+注意点)亲测
https://blog.csdn.net/qq_23979127/article/details/121454601
支付宝登录界面(示例) 亲测
https://blog.csdn.net/qq_23979127/article/details/121747279
该文章会持续更新,欢迎关注

  • 12
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

go-Forward

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值