知識(shí)
不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價(jià)值,我們?cè)谧非笃湟曈X表現(xiàn)的同時(shí),更側(cè)重于功能的便捷,營(yíng)銷的便利,運(yùn)營(yíng)的高效,讓網(wǎng)站成為營(yíng)銷工具,讓軟件能切實(shí)提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序?yàn)楹笃谏?jí)提供便捷的支持!
您當(dāng)前位置>首頁(yè) » 新聞資訊 » 小程序相關(guān) >
多樣化自定義小程序?qū)Ш綑?/h1>
發(fā)表時(shí)間:2021-1-5
發(fā)布人:葵宇科技
瀏覽次數(shù):41
效果如下隨意變換:(隨便拿了星巴克小程序圖,侵刪)
navbar-for-wxapp
一、如何實(shí)現(xiàn)
1. index.js
/*
* @Author: mtonhuang
* @Feature: 小程序自定義導(dǎo)航欄組件
*/
Component({
properties: {
titleText: { //導(dǎo)航欄文字
type: String,
value: '導(dǎo)航欄'
},
backgroundImg: { //背景圖片路徑
type: String,
value: ''
},
backIcon: { //返回按鈕
type: String,
value: ''
},
homeIcon: { //房子按鈕
type: String,
value: ''
}
},
attached: function(){
const self = this;
self.getSysmInfo();
},
data: {
},
methods: {
getSysmInfo: function() {
const self = this;
wx.getSystemInfo({
success: function(res) {
let isIos = res.system.indexOf('iOS') > -1;
let status = res.statusBarHeight;
self.setData({
navHeight: isIos ? 44 : 48,
status: status
})
}
})
},
back: function(){
this.triggerEvent('back')
},
home: function() {
this.triggerEvent('home');
}
}
})
復(fù)制代碼
2. index.wxml
<view class="nav" style="height: {{status + navHeight}}px">
<view class="index-banner" wx:if="{{backgroundImg}}">
<image class="index-banner__cover" mode="scaleToFill" src="{{backgroundImg}}"></image>
</view>
<view class="status" style="height: {{status}}px;"></view>
<view class="navbar" style="height:{{navHeight}}px;">
<view class="capsule" style="{{backIcon ? '' : 'width: 152rpx;margin-left: 24rpx'}}">
<view class="back-icon" wx:if="{{backIcon}}" bindtap="back">
<image class="imag_back" src="{{backIcon}}"></image>
</view>
<view class="home-icon" wx:if="{{homeIcon}}" bindtap="home" style="{{backIcon ? '' : 'left: 84.2rpx'}}">
<image class="imag_home" src="{{homeIcon}}"></image>
</view>
</view>
<view class="nav-title" wx:if="{{titleText}}">
<text>{{titleText}}</text>
</view>
</view>
</view>
復(fù)制代碼
二、如何使用1. 【必填】index.json
{
"navigationStyle": "custom", //自定義導(dǎo)航欄,必填
"usingComponents": {
"nav-bar": "../../components/navBar/navBar" //引入我們的組件
}
}
復(fù)制代碼
2. 【必填】index.wxml
- 給頁(yè)面的最大父級(jí) padding-top
- 引入組件,名稱為 index.json 中自定義的組件名稱 nav-bar
- 根據(jù)自己需要配置 背景圖,回退 icon,小房子按鈕,標(biāo)題文字等
<view class="page" style="padding-top: {{height + status}}px">
<nav-bar
bindback="back"
bindhome="home"
backIcon="../../assets/img/svg/back.svg"
homeIcon="../../assets/img/svg/home.svg"
titleText="這是自定義導(dǎo)航欄"
backgroundImg="test.png"
backIcon="../../assets/img/svg/back_default.svg">
</nav-bar>
</view>
復(fù)制代碼
3. 【必填】根據(jù)不同機(jī)型,計(jì)算出 height 與 status 的值
onLoad() {
let that = this;
wx.getSystemInfo({
success: function(res) {
let isIos = res.system.indexOf('iOS') > -1;
let status = res.statusBarHeight;
that.setData({
height: isIos ? 44 : 48,
status: status
})
}
})
}
復(fù)制代碼
4. 【選填】事件 back 或者 home
// 根據(jù)業(yè)務(wù)需求
back: function () {
wx.reLaunch({
url: '../index/index'
})
}
home: function () {
wx.reLaunch({
url: '../index/index'
})
}
復(fù)制代碼
5.【選填】讀者也可以自定義字體顏色等,寫法就不再贅述
Contributor
- mtonhuang
當(dāng)然,喜歡的話,請(qǐng)不要吝嗇您的start for my github blog,Thanks?(?ω?)?
相關(guān)案例查看更多
相關(guān)閱讀
- 網(wǎng)站建設(shè)選
- 云南網(wǎng)頁(yè)制作
- 用戶登錄
- 網(wǎng)絡(luò)公司
- 云南網(wǎng)站建設(shè)價(jià)格
- 買小程序被騙
- 網(wǎng)絡(luò)公司排名
- 江蘇小程序開發(fā)
- 百度快速排名
- 云南建設(shè)廳官方網(wǎng)站
- 小程序密鑰
- 云南網(wǎng)站建設(shè)哪家強(qiáng)
- 網(wǎng)站建設(shè)電話
- 報(bào)廢車拆解回收管理系統(tǒng)
- 貴州小程序開發(fā)
- 模版信息
- 云南小程序開發(fā)公司推薦
- 保險(xiǎn)網(wǎng)站建設(shè)公司
- 小程序設(shè)計(jì)
- 云南網(wǎng)站建設(shè)專家
- 網(wǎng)站維護(hù)
- 云南軟件公司
- 百度小程序開發(fā)
- 網(wǎng)站小程序
- 汽車報(bào)廢回收管理軟件
- 大理網(wǎng)站建設(shè)公司
- 手機(jī)網(wǎng)站建設(shè)
- php網(wǎng)站
- 河南小程序制作
- 云南小程序開發(fā)課程