微信小程序开发注意事项

跳转tabBar页面时,不能使用navigator标签、 wx.navigateTo、wx.redirectTo方法跳转页面,可以使用wx.switchTab(Object object)和wx.reLaunch(Object object)

延时执行

setTimeout(function(){ 
  console.log("延时1秒后执行"); 
}, 1000); 

wxss中的本地资源图片无法通过 WXSS 获取,可以使用网络图片,或者 base64,或者使用标签。

自定义导航栏

"navigationStyle":"custom"
"renderer": "skyline",

border-radius设置失效:给container元素添加overflow: hidden 或 transform: translateY(0)

是图片充满容器

<view class="location-img"><image src="" mode=""/></view>
//设置:
img{
width:100%;
height:100%
}

注意 e.currentTarget.dataset.value 和 e.targetarget.dataset.value

success不能使用this.setData

var that=this	//然后that.setData

报错:No primary or single unique constructor found for interface java.util.List

//添加
(@RequestParam(value = "arr") List<Integer> arr)

wx.getLocation({})不执行

//在app.json中添加
"requiredPrivateInfos": [
    "getLocation"
  ],

小程序做删除的时候,请求用的是delete时,按平时做GET,POST时的方式传参,后台是接收不到参数的。原因是因为传的是json格式,但是delete接口要的是query string格式的,所以就导致参数传过去,后端无法接收。 PUT也是
解决方法:

//1.手动拼接
wx.request({
            url: 'http://localhost:8080/personalinfo/delete?id='+that.data.personalInfo.id,	//手动拼接
            method: 'DELETE',
            data: {
            },
            header: { 'content-type': 'application/json' },
            success(res) {
            }
          })
//2.content-type用formData的
wx.request({
     url: "http://test/xxx",
     method:'DELETE',
     data:{id},
     header:{
         "content-type":"application/x-www-form-urlencoded"
     },

解决swiper轮播图不能占满

swiper {
  width: 100%;
  height: calc(100vw * 327 /  491);
}
image {
  width: 100%;
}

解决switchTab数据不刷新 switchTab成功跳转后调用success,此时可以拿到跳转后页面的page对象,从而调用页面onLoad方法重载页面;微信后期应该会加相应的参数来决定是否刷新跳转

wx.switchTab({
    url:../index/index’,
    success: function (e) {
        var page = getCurrentPages().pop();
        if (page == undefined || page == null) return;
        page.onLoad();
    }
})

获取当前时间

const now = new Date();  
    const year = now.getFullYear();  
    const month = this.formatNumber(now.getMonth() + 1);  
    const day = this.formatNumber(now.getDate());  
    const hours = this.formatNumber(now.getHours());  
    const minutes = this.formatNumber(now.getMinutes());  
    const currentTime = `${year}-${month}-${day} ${hours}:${minutes}`;  
    this.setData({  
      time: currentTime  
    });  

formatNumber(n) {  
    n = n.toString();  
    return n[1] ? n : '0' + n;  
  },
  • 9
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值