本篇文章解决的问题如下:
1:uniapp在pages.json中定义的tabbar,在非tabbar页面的时候不会显示,所以自定义了一个tabbar组件。(注意是自定义组件不是官方的custom-tab-bar组件)
2:有些tabbar需要动态变化,会员登陆前和会员登陆后可能会需要在tabbar上面展示不同的项目,所以要做到动态判断
3:uniapp所有页面底部都插入同一个组件(例如版权信息,或右侧悬浮的内容),每个页面都引入一次太过麻烦,所以在main.js里面挂载一次就可以所有页面使用。
一:自定义tabbar组件:(就不需要在pages.json里面再定义tabbar了)
<!--
@时间:2020-03-16
@描述:自定义底部导航栏
@使用:
在main.js全部引入:
import tabBar from "@/pages/common/tabBar.vue"
Vue.component('tabBar', tabBar)
在需要显示的页面底部添加:
<view>
<view>这里是页面内容代码区域</view> // 其中uni-p-b-98是公共样式类名,表示padding-bottom: 98upx; 设置的98upx是和底部导航栏的高度保持一致,页面的内容就不会被底部导航遮挡住啦
<view class="uni-p-b-98"></view> // 最后引入自定义组件,并传当前栏目对应的pagePath到自定义组件,显示当前栏目的选中样式
<tabBar :pagePath="'/pages/tabBar/home/home'"></tabBar>
</view>
-->
<template>
<view class="uni-tabbar">
<view class="uni-tabbar__item" v-for="(item,index) in tabbar" :key="index" @tap="changeTab(item)">
<view class="icon" :class="[item.fontIcon , item.pagePath == pagePath?'uni-active':'']"></view>
<!-- 上面使用的是字体图标,解决切换页面的时候图标会闪的效果,毕竟每切换一个页面都会闪一下不太好看,可以切换使用下面的图片方式 -->
<view v-if="false" class="uni-tabbar__bd">
<view class="uni-tabbar__icon">
<image v-if="item.pagePath == pagePath" class="uni-w-42 uni-h-42" mode="aspectFit" :src="item.selectedIconPath"></image>
<image v-else class="uni-w-42 uni-h-42" mode="aspectFit" :src="item.iconPath"></image>
</view>
</view>
<view class="uni-tabbar__label" :class="{'active': item.pagePath == pagePath}">
{{item.text}}
</view>
</view>
</view>
</template>
<script>
export default {
props: {
pagePath: null
},
data() {
return {
page: 'contact',
showPage: false,
containerHeight: 400,
tabbar: [
{
"pagePath": "/pages/tabBar/home/home",
"iconPath": "/static/tabBar/home.png",
"selectedIconPath": "/static/tabBar/home_col.png",
"text": "首页",
"fontIcon": "icon-shouye"
}, // 这里是要动态切换的栏目,先隐藏,动态追加
// {
// "pagePath": "/pages/tabBar/manage/manage",
// "iconPath": "/static/tabBar/home.png",
// "selectedIconPath": "/static/tabBar/home_col.png",
// "text": "管理",
// "fontIcon": "icon-guanli"
// },
{
"pagePath": "/pages/tabBar/person/person",
"iconPath": "/static/tabBar/person.png",
"selectedIconPath": "/static/tabBar/person_col.png",
"text": "我的",
"fontIcon": "icon-wode"
}
]
};
},
mounted() {
// true为判断条件,根据实际的需求替换即可
if(true) {
this.tabbar.splice(1,0,
{
"pagePath": "/pages/tabBar/manage/manage",
"iconPath": "/static/tabBar/home.png",
"selectedIconPath": "/static/tabBar/home_col.png",
"text": "管理",
"fontIcon": "icon-guanli"
}
)
}
},
methods: {
changeTab(item) {
this.page = item.pagePath; // 这里使用reLaunch关闭所有的页面,打开新的栏目页面
uni.reLaunch({
url: this.page
});
},
}
}
</script>
<style lang="scss" scoped>
[nvue] uni-scroll-view, [nvue] uni-swiper-item, [nvue] uni-view {
flex-direction: unset;
}
[nvue-dir-column] uni-swiper-item, [nvue-dir-column] uni-view {
flex-direction: unset;
}
.uni-tabbar {
position: fixed;
bottom: 0;
z-index: 999;
width: 100%;
display: flex;
justify-content: space-around;
height: 98upx;
padding: 16upx 0;
box-sizing: border-box;
border-top: solid 1upx #ccc;
background-color: #fff;
box-shadow: 0px 0px 17upx 1upx rgba(206, 206, 206, 0.32);
.uni-tabbar__item {
display: block;
line-height: 24upx;
font-size: 20upx;
text-align: center;
}
.uni-tabbar__icon {
height: 42upx;
line-height: 42upx;
text-align: center;
}
.icon {
display: inline-block;
}
.uni-tabbar__label {
line-height: 24upx;
font-size: 24upx;
color: #999;
&.active {
color: #1ca6ec;
}
}
}
</style>
然后在各页面中使用组件即可
**注意修改代码中的页面路径**
**注意使用字体图标的话需要先在APP.Vue中引入iconfont.css**
<tabBar :pagePath="'/pages/list/list'"></tabBar>
**传入的路径用于当前项目高亮**
二:全局挂载自定义组件(在main.js中)
import Vue from 'vue'
Vue.prototype.baseUrl = tools.baseUrl
Vue.config.productionTip = false
import tabBar from "@/components/tabbar/tabbar.vue"
Vue.component('tabBar', tabBar)
import Aside from "@/components/aside/aside.vue"
Vue.component('Aside', Aside)
**注意要放在import Vue之后才行**
然后在各个页面中无须再import,也无须再components注册,直接<Aside></Aside>就可以用了。
我正在尝试设置一个puppet节点,但rubygems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由rubygems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby
我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer
我想向我的Controller传递一个参数,它是一个简单的复选框,但我不知道如何在模型的form_for中引入它,这是我的观点:{:id=>'go_finance'}do|f|%>Transferirde:para:Entrada:"input",:placeholder=>"Quantofoiganho?"%>Saída:"output",:placeholder=>"Quantofoigasto?"%>Nota:我想做一个额外的复选框,但我该怎么做,模型中没有一个对象,而是一个要检查的对象,以便在Controller中创建一个ifelse,如果没有检查,请帮助我,非常感谢,谢谢
我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby1.9+ 关于ruby-主要:Objectwhenrun
我有一些代码在几个不同的位置之一运行:作为具有调试输出的命令行工具,作为不接受任何输出的更大程序的一部分,以及在Rails环境中。有时我需要根据代码的位置对代码进行细微的更改,我意识到以下样式似乎可行:print"Testingnestedfunctionsdefined\n"CLI=trueifCLIdeftest_printprint"CommandLineVersion\n"endelsedeftest_printprint"ReleaseVersion\n"endendtest_print()这导致:TestingnestedfunctionsdefinedCommandLin
我有一个只接受一个参数的方法:defmy_method(number)end如果使用number调用方法,我该如何引发错误??通常,我如何定义方法参数的条件?比如我想在调用的时候报错:my_method(1) 最佳答案 您可以添加guard在函数的开头,如果参数无效则引发异常。例如:defmy_method(number)failArgumentError,"Inputshouldbegreaterthanorequalto2"ifnumbereputse.messageend#=>Inputshouldbegreaterthano
我使用Ember作为我的前端和GrapeAPI来为我的API提供服务。前端发送类似:{"service"=>{"name"=>"Name","duration"=>"30","user"=>nil,"organization"=>"org","category"=>nil,"description"=>"description","disabled"=>true,"color"=>nil,"availabilities"=>[{"day"=>"Saturday","enabled"=>false,"timeSlots"=>[{"startAt"=>"09:00AM","endAt"=>
我想获取模块中定义的所有常量的值:moduleLettersA='apple'.freezeB='boy'.freezeendconstants给了我常量的名字:Letters.constants(false)#=>[:A,:B]如何获取它们的值的数组,即["apple","boy"]? 最佳答案 为了做到这一点,请使用mapLetters.constants(false).map&Letters.method(:const_get)这将返回["a","b"]第二种方式:Letters.constants(false).map{|c
我正在阅读一本关于Ruby的书,作者在编写类初始化定义时使用的形式与他在本书前几节中使用的形式略有不同。它看起来像这样:classTicketattr_accessor:venue,:datedefinitialize(venue,date)self.venue=venueself.date=dateendend在本书的前几节中,它的定义如下:classTicketattr_accessor:venue,:datedefinitialize(venue,date)@venue=venue@date=dateendend在第一个示例中使用setter方法与在第二个示例中使用实例变量之间是
我正在使用RubyonRails3.0.9,我想生成一个传递一些自定义参数的link_toURL。也就是说,有一个articles_path(www.my_web_site_name.com/articles)我想生成如下内容:link_to'Samplelinktitle',...#HereIshouldimplementthecode#=>'http://www.my_web_site_name.com/articles?param1=value1¶m2=value2&...我如何编写link_to语句“alàRubyonRailsWay”以实现该目的?如果我想通过传递一些