在全局文件中配置tabBar时需要注意哪些?

2021-02-05 09:00发布

3条回答

Q:tabBar 的位置是否支持设置成顶部?

A:tabBar 的位置暂不支持自定义设置。

Q:如何监听 tabBar 点击事件?

A:在小程序页面中用 onTabItemTap 即可监听 tabBar 点击事件。

Q:tabBar 的 icon 图标是否支持 svg 格式?

A:不支持 svg 格式,只支持 png/jpeg/jpg 图片格式。

Q:如何设置 tab 的样式?

A:可以在 JSON 文件中直接设置样式(示例代码如下所示),或者调用 my.setTabBarStyle API 进行设置。

 "tabBar": {
   "textColor": "#404040",
   "selectedColor": "#108ee9",
   "backgroundColor": "#F5F5F9"
 }


请求异常类 FAQ

Q:切换 tabBar 时报错“Cannot read property 'getCurrentPages' of undefined”,如何处理?

A:tabBar 路径错误导致,请检查 tabBar 路径。

Q:跳转页面后,为何不显示 tabBar 呢?

A:通过页面跳转(my.navigateTo)或者页面重定向(my.redirectTo)所到达的页面,不会显示底部的 tab 栏。另外,tabBar 的第一个页面必须是首页。

Q:小程序进入 tabBar 页面,如何获取上一级页面路径呢?

A:在进入页面的时候将当前页面路径存入全局,在切换 tabBar 页面的时候拿全局的地址属性即可获取上一级页面路径。


浅浅77
3楼 · 2021-02-07 09:38

先贴代码:

jQuery.fn.extend({uploadPreview: function(opts) {var _self = this,_this = $(this);opts = jQuery.extend({Img: "ImgPr",Width: 100,Height: 100,ImgType: ["gif", "jpeg", "jpg", "bmp", "png"],Callback: function() {}}, opts || {});_self.getObjectURL = function(file) {var url = null;if (window.createObjectURL != undefined) {url = window.createObjectURL(file);} else if (window.URL != undefined) {url = window.URL.createObjectURL(file);} else if (window.webkitURL != undefined) {url = window.webkitURL.createObjectURL(file);}return url;}_this.change(function() {if (this.value) {if (!RegExp("\.(" + opts.ImgType.join("|") + ")$", "i").test(this.value.toLowerCase())) {alert("选择文件错误,图片类型必须是" + opts.ImgType.join(",") + "中的一种");this.value = "";return false;}if (navigator.userAgent.indexOf("MSIE") > -1) {try {$("#" + opts.Img).attr('src', _self.getObjectURL(this.files[0]));} catch (e) {var src = "";var obj = $("#" + opts.Img);var div = obj.parent("div")[0];_self.select();if (top != self) {window.parent.document.body.focus();} else {_self.blur();}src = document.selection.createRange().text;document.selection.empty();obj.hide();obj.parent("div").css({'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)','width': opts.Width + 'px','height': opts.Height + 'px'});div.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = src;}} else {$("#" + opts.Img).attr('src', _self.getObjectURL(this.files[0]));}opts.Callback();}});}});

*使用方法:  

把需要进行预览的IMG标签外 套一个DIV 然后给上传控件ID给予uploadPreview事件

$("#up").uploadPreview({ Img: "ImgPr", Width: 120, Height: 120, ImgType: ["gif", "jpeg", "jpg", "bmp", "png"], Callback: function () { }});   

另外注意一下 使用该插件预览图片 选择文件的按钮在IE下不能是隐藏的 你可以换种方式隐藏 比如:top left 负几千像素 

js实现的方法:

//js本地图片预览,兼容ie[6-9]、火狐、Chrome17+、Opera11+、Maxthon3function PreviewImage(fileObj,imgPreviewId,divPreviewId){var allowExtention=".jpg,.bmp,.gif,.png";//允许上传文件的后缀名document.getElementById("hfAllowPicSuffix").value;var extention=fileObj.value.substring(fileObj.value.lastIndexOf(".")+1).toLowerCase();var browserVersion= window.navigator.userAgent.toUpperCase();if(allowExtention.indexOf(extention)>-1){if(fileObj.files){//HTML5实现预览,兼容chrome、火狐7+等if(window.FileReader){var reader = new FileReader();reader.onload = function(e){document.getElementById(imgPreviewId).setAttribute("src",e.target.result);}reader.readAsDataURL(fileObj.files[0]);}else if(browserVersion.indexOf("SAFARI")>-1){alert("不支持Safari6.0以下浏览器的图片预览!");}}else if (browserVersion.indexOf("MSIE")>-1){if(browserVersion.indexOf("MSIE 6")>-1){//ie6document.getElementById(imgPreviewId).setAttribute("src",fileObj.value);}else{//ie[7-9]fileObj.select();if(browserVersion.indexOf("MSIE 9")>-1)fileObj.blur();//不加上document.selection.createRange().text,因为在ie9会拒绝访问var newPreview =document.getElementById(divPreviewId+"New");if(newPreview==null){newPreview =document.createElement("div");newPreview.setAttribute("id",divPreviewId+"New");newPreview.style.width = document.getElementById(imgPreviewId).width+"px";newPreview.style.height = document.getElementById(imgPreviewId).height+"px";newPreview.style.border="solid 1px #d2e2e2";}newPreview.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale',src='" + document.selection.createRange().text + "')";var tempDivPreview=document.getElementById(divPreviewId);tempDivPreview[removed].insertBefore(newPreview,tempDivPreview);tempDivPreview.style.display="none";}}else if(browserVersion.indexOf("FIREFOX")>-1){//firefoxvar firefoxVersion= parseFloat(browserVersion.toLowerCase().match(/firefox\/([\d.]+)/)[1]);if(firefoxVersion<7 fileObj.value="">-1){fileObj.select();document.selection.clear();}fileObj.outerHTML=fileObj.outerHTML;}}

小磊子
4楼 · 2021-02-07 09:43
  1. "color": "#8a8a8a",

  2. "selectedColor": "#f40",//选中的颜色

  3. "backgroundColor": "#ffffff",//背景色

  4. "borderStyle": "black",//边界线的颜色

  5. "position":"top",//位置,是在上边。还是选择在下边,如果选择top,就不会显示图标

  6. "list": [//组件的清单

  7. {

  8. "pagePath": "page/component/index",//页面路径

  9. "text": "组件",//组件上显示的文字

  10. "iconPath": "img/compont_un.png",//默认图标

  11. "selectedIconPath": "img/compont_on.png"//选中后的图标

  12. },

  13. {

  14. "pagePath": "page/API/index",

  15. "text": "API",

  16. "iconPath": "img/API_un.png",

  17. "selectedIconPath": "img/API_on.png"

  18. },

  19. {

  20. "pagePath": "page/persion/index",

  21. "text": "我的",

  22. "iconPath": "img/我的_un.png",

  23. "selectedIconPath": "img/我的_on.png"

  24. },

  25. {

  26. "pagePath": "pages/logs/logs",

  27. "text": "日志",

  28. "iconPath": "img/日志.png",

  29. "selectedIconPath": "img/日志_on.png"

  30. }

  31. ]



相关问题推荐

  • 回答 120

    相对前几年来说,要高上不少了,毕竟入行的人也是越来越多了,基础的工作对应想要参与的人群基数越来越大,但是对于高端人才的需求还是很多,人才还是相对稀缺性的。所以,想要学web或者其他技术也一样,别等,别观望。web前端就业方向特别多包括web前端开发...

  • 回答 25

    相对定位和绝对定位是定位的两种表现形式,区别如下:一、主体不同1、相对定位:是设置为相对定位的元素框会偏移某个距离。2、绝对定位:absolute 脱离文档流,通过 top,bottom,left,right 定位。二、特点不同1、相对定位:在使用相对定位时,无论是否进行移...

  • 抓包是什么意思?2020-04-01 17:36
    回答 7
    已采纳

    抓包(packet capture)就是将网络传输发送与接收的数据包进行截获、重发、编辑、转存等操作,也用来检查网络安全。抓包也经常被用来进行数据截取等。抓包可以通过抓包工具来查看网络数据包内容。通过对抓获的数据包进行分析,可以得到有用的信息。目前流行的...

  • 回答 89

    常用的前端框架有Bootstrap框架、React框架、Vue框架、Angular框架、Foundation框架等等

  • 回答 65
    已采纳

    前端是目的就业前景非常不错的一个计算机技术,但是自学的话还是有一定难度的,网络上自学是碎片化的,同时互联网技术跟新换代快,自己的话比较吃力也学习不到最新的技术。

  • SSR 是什么意思?2020-03-20 18:56
    回答 6

    SSR就是一台服务器,可以利用 SSR 在远程的服务器上配置 SSR,使其能够成为 SSR 节点,这样本地电脑或者其它设备利用 SSR 节点实现 VPN 或者远程上网及游戏加速等方面。ShadowsocksR(简称 SSR)是 Shadowsocks 分支,在 Shadowsocks 的基础上增加了一些数据...

  • 回答 52
    已采纳

    计算机培训方向比较多,建议找适合自己的方向选择培训编程类:JAVA、WEB、Python、C/C++、C#等测试类:软件测试运维类:云计算、网络安全设计类:UI设计、3D建模等

  • 回答 11

    1、代码判断xAxis: {type: &#39;time&#39;,splitLine: {show: false},interval: 3600, // 设置x轴时间间隔axisLabel: {formatter: function(value, index) {return liangTools.unix2hm(value)}}},首先要把xAxis 显示类型设置成time,然后设置对应X轴......

  • 回答 8

    HTML5 + CSS + JavaScript 开发 跨平台重用代码 

  • 回答 4

    采用rem单位自动响应,并提供独有栅格化系统快速定义宽高、边距节省css代码量,同时总结各大型移动端网页,提供一套ui颜色搭配规范,尺寸规范,字体规范等。

  • 回答 10

    iView UI、ioni、SUI

  • 回答 6

     jQTouch 

  • 回答 4

    如果只是普通的移动端用vue react 或者dva 如果是要编译成小程序什么的或者混生 就用uni-app(对应vue语法)taro(对应react) 或者纯原生 这个没有限制的,自己怎么舒服怎么来

  • 回答 4

    因为可以运用在网页和小程序的开饭中,而且开源,用着便宜,企业都很喜欢

  • 回答 10

    一、Visual Studio Code下载地址:https://code.visualstudio.com/微软在2015年4月30日Build 开发者大会上正式宣布了 Visual Studio Code 项目:一个运行于 Mac OS X、Windows和 Linux 之上的,针对于编写现代 Web 和云应用的跨平台源代码编辑器。Visual Stud...

  • 回答 9

    jQuery自带淡入淡出效果 https://www.w3school.com.cn/jquery/jquery_fade.asp 看看这个 

没有解决我的问题,去提问