微信小程序常见功能
前言
总结下小程序开发中,拨打电话、自定义顶部栏、使用本机字体等常见功能整理;
一、使用本机字体
css中更改font-family;
.page{
font-family:Monospaced Number,Chinese Quote,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,PingFang SC,Hiragino Sans GB,Microsoft YaHei,Helvetica Neue,Helvetica,Arial,sans-serif!important;
}
二、自定义透明顶部栏
顶部栏透明可以显示轮播图及图片,这个功能在单页面和总页面都可以完成,在json文件中配置;
- 顶部栏透明可以显示轮播图及图片:
"navigationStyle": "custom"
; - navigationBarTitleText:导航栏文字
- navigationBarTextStyle:标题颜色(black / white)
- backgroundColor:胶囊按钮的颜色;
- 其他配置:微信小程序导航的配置
{
"usingComponents": {
},
"backgroundTextStyle": "dark",
"navigationStyle": "custom",
"navigationBarTitleText": "小程序标题",
"navigationBarTextStyle": "white"
}
三、拨打电话
官方提供了API
callPhone() {
wx.makePhoneCall({
phoneNumber: '18100002222',
success: function () {
console.log('拨打成功')
},
fail: function () {
console.log('拨打失败')
},
})
},
四、获取用户信息
原本官方提供了API,但是新版目前版本,只能用按钮操作!直接调用API不生效,设置open-type="getUserInfo"
及bindgetuserinfo="getUserInfo"
就可获取到用户信息;
<button bindgetuserinfo="getUserInfo" open-type="getUserInfo">
微信登录
</button>
展示页可以直接使用open-data
展示,无需操作保存userInfo;
附:open-data中type 的合法值
<view class="isLogin" >
头像:<open-data type="userAvatarUrl"></open-data>
微信名:<open-data type="userNickName"></open-data>
</view>
五、动态设置图片地址
将路径绑定到data,中即可动态设置图片地址;
<image src="{
{qrCodePath}}" mode="widthFix" />
Page({
data: {
qrCodePath: '',
},
onLoad(){