第一次使用mpvue开发,遇到的问题还是挺多的:
1、登录授权 (监听:“拒绝”、“授权”)
<button open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">授权登录</button>
bindGetUserInfo: function(e) {
console.log(e) //这里可以收到拒绝或允许的消息
}
这个是原生的,这样写在mpvue里是不可以的。@getuserinfo
<button
class='testbutton'
open-type="getUserInfo"
@getuserinfo="getuserinfo"
withCredentials="true"
>
// 获取点击的是“拒绝” 还是 “授权”
getuserinfo: function(e){
// 这里监听是否是点击了“拒绝” 或“允许”
if(e.target['userInfo']){
console.log('授权通过')
// 去到我的详情
wx.navigateTo({
url: '../../pages/me/main'+e.target.userInfo,
})
}else{
console.log('拒绝授权')
wx.showModal({
title: '您选择了拒绝授权!'
})
}
}
2、传值
//你以为是iOS吗???
wx.navigateTo({
url: '../order/pay?cartId=&attrId' +data.cart_id +data.attrid ,
});
// 需要这样:
wx.navigateTo({
url: '../order/pay?cartId='+data.cart_id+'&attrId=' +data.attrid ,
});
补充:
如果是传对象的话,例如: {xxx:'',xxx:'''} ,稍微多一点、字符复杂的话,直接传过去是没有用的:
使用:
encodeURIComponent
// post 提交时 的JSON格式转换!!!
export function json2Form(json) {
var str = [];
for(var p in json){
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(json[p]));
}
return str.join("&");
}
export default {
json2Form,
}
使用直接引入这个js文件,然后再调用该方法就可以了。
3、存值,不支持 localstorage
wx.setStorageSync("userInfo",that.userInfo)
// 如果是这样写:我是没拿到值(不知你们是否可以)
wx.setStorage({
key:"key",
data:"value"
})
3、还有...忙!!!很多笔记没时间整理
网友评论