微信小程序开发避坑

发布时间 2023-07-05 12:39:07作者: 混名汪小星

1.wx.showModal 未报错,也未执行。

title 必须为string类型

wx.showModal({
      title: res.statusCode,
      content: '错误码:' + res.statusCode, 
      showCancel: false,
      complete() {
        isShow = false
      }
    })

2.map组件 移动marker 闪烁

不能直接更改marker中的坐标点,否则移动时会出现图标闪烁
解决办法 :

onReady() {
    mapContext = wx.createMapContext('map');
  },
// 在合适的事件中调用移动 marker 的方法
moveMarker() {
  mapContext.translateMarker({
    markerId: 1, // marker 的唯一标识符
    destination: {
      latitude: 39.908823, // 目标位置的纬度
      longitude: 116.397470, // 目标位置的经度
    },
    autoRotate: true, // 是否自动旋转 marker
    rotate: 90, // 旋转角度
    duration: 2000, // 移动到目标位置的过程时间,单位为毫秒
    animationEnd() {
      console.log('Marker moved!');
    },
  });
},