Taro,前端如何对接微信物流查询插件

本文介绍了如何在Taro小程序中配置微信物流查询组件,包括在app.config.ts中的配置,处理因插件导致的打包体积问题,以及在项目中使用和遇到的常见错误及解决方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

taro小程序开发 对接微信物流查询组件(一切的基础在于 后台配置了这个插件)

一、在app.config.ts中进行配置

由于插件的使用可能导致打包体积过大,采取分包加载的形式,将插件写入要使用的包中

export default defineAppConfig({
  pages: [
    'pages/home/default/index', 
    'pages/tab1/default/index', 
    'pages/tab2/default/index', 
    'pages/tab3/index', 
  ],
  subpackages: [
    {
      root: 'packageA',
      name: 'packageA',
      pages: [
        'project/index', 
        'project/video-play', 
      ],
    },
    {
      root: 'packageB',
      name: 'packageB',
      pages: [
        'address/index', 
        'address/addAddress/index', 
      ],
      // 添加插件需要授权使用
      plugins: {
        logisticsPlugin: {
          version: '2.2.19',
          provider: 'wx9ad912bf20548d92',
        },
      },
    },
  ],
  window: {
    backgroundTextStyle: 'light',
    navigationBarBackgroundColor: '#fff',
    navigationBarTitleText: 'xxxxxxxxx',
    navigationBarTextStyle: 'black',
  },
  tabBar: {
    position: 'bottom',
    selectedColor: '#44CBB4',
    borderStyle: 'black',
    list: [
      {
        pagePath: 'picUrl',
        text: '首页',
        iconPath: 'picUrl',
        selectedIconPath: 'picUrl',
      },
      {
        pagePath: 'picUrl',
        text: 'tab2',
        iconPath: 'picUrl',
        selectedIconPath: 'picUrl',
      },
      {
        pagePath: 'picUrl',
        text: 'tab3',
        iconPath: 'picUrl',
        selectedIconPath: 'picUrl',
      },
      {
        pagePath: 'picUrl',
        text: 'tab4',
        iconPath: 'picUrl',
        selectedIconPath: 'picUrl',
      },
    ],
  },

});

二、常见错误

在app.config.ts注册插件之后,再次运行yarn dev:weapp运行项目可能会遇到一些错误

TypeError: Function.prototype.apply was called on WeakMap.prototype.get, which is a string and not a function

解决这个错误 安装qs指定版本即可

yarn add qs@6.9.6  / npm install qs@6.9.6  安装qs指定版本依赖包

三、使用

  import Taro, { requirePlugin } from '@tarojs/taro';
    const plugin = requirePlugin('logisticsPlugin');

  //此接口由后端提供
  const goLogistics = async (id) => {
    const { data } = await getDeliver({
      id: id, //订单id
      appid: '传入自己的appid',
    });
    const { waybill_token } = JSON.parse(data);
    // 物流插件
    plugin.openWaybillTracking({
      waybillToken: waybill_token,
    });
  };

ps: 物流查询插件只能查询通过微信支付的订单

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值