网站建设与管理实验目的,门户网站建设采购,wordpress 炫酷博客,西宁制作网站需要多少钱文章目录 1. 实现效果2. App.vue3. pages.json 配置自定义4. 顶部导航栏 使用 微信小程序自定义 navigationBar 顶部导航栏#xff0c;兼容适配所有机型 1. 实现效果 2. App.vue
在App.vue 中#xff0c;设置获取的 StatusBar#xff0c;CustomBar 高度#xff08;实现适配… 文章目录 1. 实现效果2. App.vue3. pages.json 配置自定义4. 顶部导航栏 使用 微信小程序自定义 navigationBar 顶部导航栏兼容适配所有机型 1. 实现效果 2. App.vue
在App.vue 中设置获取的 StatusBarCustomBar 高度实现适配高度写法uni.getSystemInfo 获取可视区域的高度wx.getMenuButtonBoundingClientRect() 胶囊按钮位置信息
scriptimport Vue from vueexport default {onLaunch: function() {uni.getSystemInfo({success: function(e) {// #ifndef MPVue.prototype.StatusBar e.statusBarHeight;if (e.platform android) {Vue.prototype.CustomBar e.statusBarHeight 50;} else {Vue.prototype.CustomBar e.statusBarHeight 45;};// #endif// #ifdef MP-WEIXINVue.prototype.StatusBar e.statusBarHeight;let custom wx.getMenuButtonBoundingClientRect();Vue.prototype.Custom custom;Vue.prototype.CustomBar custom.bottom custom.top - e.statusBarHeight 4;// #endif // #ifdef MP-ALIPAYVue.prototype.StatusBar e.statusBarHeight;Vue.prototype.CustomBar e.statusBarHeight e.titleBarHeight;// #endif}});},onShow: function() {console.log(App Show)},onHide: function() {console.log(App Hide)}}
/scriptstyle langscss
/style
3. pages.json 配置自定义
pages: [{path: home,style: {navigationStyle: custom}
}]4. 顶部导航栏 使用
组件完整代码CSS 部分 我使用的是 colorUI 不懂的可以看看写法
templateviewview classcu-custom :style[{height:CustomBar px}]view classcu-bar fixed :stylestyle :class[bgImage!?none-bg text-white bg-img:,bgColor]view classaction tapBackPage v-ifisBacktext classcuIcon-back/textslot namebackText/slot/viewview classcontent :style[{top:StatusBar px}]slot namecontent/slot/viewslot nameright/slot/view/view/view
/templatescriptexport default {data() {return {StatusBar: this.StatusBar,CustomBar: this.CustomBar};},name: cu-custom,computed: {style() {var StatusBar this.StatusBar;var CustomBar this.CustomBar;var bgImage this.bgImage;var style height:${CustomBar}px;padding-top:${StatusBar}px;;if (this.bgImage) {style ${style}background-image:url(${bgImage});;}return style}},props: {bgColor: {type: String,default: },isBack: {type: [Boolean, String],default: false},bgImage: {type: String,default: },},methods: {BackPage() {uni.navigateBack({delta: 1});}}}
/scriptstyle langscss scoped
/stylemain.js 全局注册顶部导航栏组件
// 此处为引用自定义顶部
import cuCustom from ./colorui/components/cu-custom.vue
Vue.component(cu-custom,cuCustom);页面使用导航栏组件
cu-custom classnavBox bgColorbg-gradual-blue :isBacktrueblock slotbackText返回/blockblock slotcontent首页/block
/cu-custom