小程序常用代码

WPing丶

2022-04-11 15:40

//小程序中地址栏?后面的参数获取方法,JS中的onload方法
onLoad(t) {
    t.id;//
}
//小程序动态设置页面标题
wx.setNavigationBarTitle({
  title: '当前页面'
})
//小程序动态设置页面标题的颜色和背景等
wx.setNavigationBarColor({
  frontColor: '#ffffff',
  backgroundColor: '#ff0000',
  animation: {
    duration: 400,
    timingFunc: 'easeIn'
  }
})
//js方法获取前端页面传值
changeStatus:function(t) {
    var status = t.currentTarget.dataset.status;//status就是前台设置的名字data-status
}
//小程序对象转数组
var arr = Object.getOwnPropertyNames(obj);
//小程序请求接口
getApp().request({
    url: getApp().api.default.shop_detail,
    method: "GET",
    data: {
        shop_id: e.shop_id
    },
    success: function(e) {
        if (0 == e.code) {
            o.setData(e.data);
            var t = e.data.shop.content ? e.data.shop.content : "<span>暂无信息</span>";
            WxParse.wxParse("detail", "html", t, o);
        } else getApp().core.showModal({
            title: "提示",
            content: e.msg,
            showCancel: !1,
            success: function(e) {
                e.confirm && getApp().core.redirectTo({
                    url: "/pages/shop/shop"
                });
            }
        });
    },
    complete: function() {
        getApp().core.hideLoading();
    }
});
小程序跳转页面方法
三个跳转页面的不同:
wx.navigateTo:保留当前页面,跳转到小程序内的某个页面,但是不能跳到tabbar设置的页面。
wx.redirectTo:关闭当前页面,跳转到应用内的某个页面,但是不允许跳转到 tabbar设置的 页面。
wx.switchTab:跳转到tabBar页面,并关闭其他所有tabBar页面。
这三种跳转页面的方法传参也都是需要在地址后面以‘?’拼接。
wx.navigateTo({
    url: '../digitalkeyboard/digitalkeyboard?去另一个页面要用来获取的参数名=' + 需要传参的变量或值
})
wx.redirectTo({
    url: '../digitalkeyboard/digitalkeyboard?去另一个页面要用来获取的参数名=' + 需要传参的变量或值
})
wx.switchTab({
    url: '../digitalkeyboard/digitalkeyboard?去另一个页面要用来获取的参数名=' + 需要传参的变量或值
})
小程序input框type:number=数字键盘;digit=带小数点的数字键盘
0 条评论

评论:

发送
0.091603s