说说最近吧,在公司项目需求开发一款uni-app的App。说说自己遇到的坑,目前还在开发阶段,一个人独立开发阶段。
废话不多说了,直接来干货!!!有图有代码
1 、小程序授权怎么登录授权呢
这是小程序更新后需要在button上添加几个主要的属性
<button hover-class="none" open-type="getUserInfo" type="primary" @getuserinfo="getUserInfo">确认授权</button>
//hover-class这个是取消了button按下取消高亮,颜色给的竟然是绿色的哈哈哈~~~实在是辣眼睛
//open-type 这个是小程序更新以后必须要添加的属性之一
//@getuserinfo 切记不是@click 这是官方自带的事件,去弹出授权弹框的
下面是script中代码
export default {
data() {
return {
code: ""
};
},
created: function() {
let _this = this;
uni.login({
provider: 'weixin',
success: function(res) {
_this.code = res.code;
}
});
},
methods: {
getUserInfo(e) {
//在这里就可以获得用户信息了
console.log(e)
//存储到storage当中
uni.setStorageSync("Token", e.detail.encryptedData)
}
}
</script>
2、跳转路由怎么拿到id
//跳转路由进行传参
uni.navigateTo({
url: `organizationOne?id=${id}`
})
在organizationOne页面中
onLoad(open){
console.log(open.id) //这个就是你想要的id
}
3、页面要实时更新怎么处理
//用onShow生命周期去接受它的方法
onShow(){
this.activityList(); //这是自定义的方法
},
methods:{
activityList(){
uni.request({ //这里填写你要请求的数据
)}
}
4、创建按钮时,要有一个login页面
methods:{
activityList(){
uni.showLoading({ //logo效果
title:"加载中", //文字
mask:true //是否点击穿透 默认是false
})
uni.request({ //这里填写你要请求的数据
//在你请求完的数据后面添加
setTimeout(function () { //设置时间
uni.hideLoading(); //关闭logo效果 需要你手动添加
}, 1500);
)}
}
}
5、有创建活动页面时,有用到< textarea >标签时候,在手机测试时,发现placeholde文字占位,是因为你这个页面有哪些元素设置了overflow,禁用了就行了
// overflow: auto;
6、input如何禁用 在标签上设置 disabled=“disabled” 即可
<input type="text" placeholder-style="color:#AAAAAA;" :value="item.route_ipt" disabled="disabled">
先总结到这,下次总结一下uni-app封装请求,提升自己的逼格。