当前位置:   article > 正文

vue 项目移动端 ios 安卓 pc端适配 实现一个底部tab栏_uview van-tabbar-item ios

uview van-tabbar-item ios

插件         

H5移动端控制台调试--    npm install vconsole

安装插件可适配移动端--   npm i lib-flexible -- save-dev

安装插件可适配PC px2rem loader--     npm install px2rem-loader --save-dev

 

1.在main.js中引入 lib-flexibl

      

2.配置px2rem-loader
   在build文件中找到util.js,将px2rem-loader添加到cssLoaders中,如:

   

 3.同时,在generateLoaders方法中添加px2remLoader

 

4.ios--通过媒体查询样式适配

  1. /*iPhone X 适配*/
  2. @media only screen and (device-width375pxand (device-height812pxand (-webkit-device-pixel-ratio3) {
  3.  .fixed-bottom{
  4. bottom37px;
  5. }
  6. }
  7. /*iPhone XS max 适配*/
  8. @media only screen and (device-width414pxand (device-height896pxand (-webkit-device-pixel-ratio:3) {
  9.  .fixed-bottom{
  10. bottom37px;
  11. }
  12. }
  13. /*iPhone XR max 适配*/
  14. @media only screen and (device-width414pxand (device-height896pxand (-webkit-device-pixel-ratio:2) {
  15. .fixed-bottom{
  16. bottom37px;
  17. }
  18. }

5.ios--通过css样式适配,

如何适配:通过meta标签设置网页在可视窗口的布局方式新增 viweport-fit 属性,使得页面内容完全覆盖整个窗口:

  1. env()和constant(),是IOS11新增特性,Webkit的css函数,用于设定安全区域与边界的距离,有4个预定义变量:
  2. safe-area-inset-left:安全区域距离左边边界的距离
  3. safe-area-inset-right:安全区域距离右边边界的距离
  4. safe-area-inset-top:安全区域距离顶部边界的距离
  5. safe-area-inset-bottom :安全距离底部边界的距离
  6. <meta name="viewport" content="width=device-width, viewport-fit=cover">
  7. 你需要哪里去兼容iphone x 的底部刘海屏就在那个页面写这两行代码就可以了
  8. padding-bottom: constant(safe-area-inset-bottom); /* 兼容 iOS < 11.2 */
  9. padding-bottom: env(safe-area-inset-bottom); /* 兼容 iOS >= 11.2 */
  10. 另外在你的父元素设置高度也可以实现
  11. max-height: calc(100vh - 41px);
  12. 设置最大高度 100vh就是你视口的高度,通过calc属性-去你底部导航栏的高度

6.移动端使用van-tabbar实现一个底部tab栏点击高亮

  1. <template>
  2. <van-tabbar
  3. v-model="active"
  4. @change="changeTab"
  5. safe-area-inset-bottom
  6. >
  7. <van-tabbar-item replace v-for="(item, index) in tabbarList" :key="index">
  8. <span>{{ item.title }}</span>
  9. <img slot="icon" slot-scope="props" :src="props.active ? item.active : item.normal" />
  10. </van-tabbar-item>
  11. </van-tabbar>
  12. </template>
  13. <script>
  14. export default {
  15. data() {
  16. return {
  17. active: 0,
  18. tabbarList: [
  19. {
  20. // title: "首页",
  21. normal: require("../../src/assets/menu/home_icon.png"),
  22. // normal:"http://sucai.suoluomei.cn/sucai_zs/images/20200810093544-20180626194653.png",
  23. // active:"http://sucai.suoluomei.cn/sucai_zs/images/20200808142214-20.png"
  24. active: require("../../src/assets/menu/active-home.png")
  25. },
  26. {
  27. // title: "禾粉圈",
  28. // normal:"http://sucai.suoluomei.cn/sucai_zs/images/20200810093806-20180626194643.png",
  29. // active:"http://sucai.suoluomei.cn/sucai_zs/images/20200810093651-20180626191313.png"
  30. normal:require("../../src/assets/menu/supportn_icon.png"),
  31. active:require("../../src/assets/menu/active-supportn.png")
  32. },
  33. {
  34. // title: "列表",
  35. // normal:"http://sucai.suoluomei.cn/sucai_zs/images/20200810093806-20180626194643.png",
  36. // active:"http://sucai.suoluomei.cn/sucai_zs/images/20200810093651-20180626191313.png"
  37. normal:require("../../src/assets/menu/shop_icon.png"),
  38. active:require("../../src/assets/menu/active-shop.png")
  39. },
  40. {
  41. // title: "我的",
  42. // normal:"http://sucai.suoluomei.cn/sucai_zs/images/20200808112146-1.png",
  43. // active:"http://sucai.suoluomei.cn/sucai_zs/images/20200810093931-20180627092356.png"
  44. normal:require("../../src/assets/menu/profile_icon.png"),
  45. active:require("../../src/assets/menu/activeprofile_icon.png")
  46. }
  47. ]
  48. };
  49. },
  50. mounted() {
  51. this.watchTab();
  52. },
  53. methods: {
  54. changeTab(e) {
  55. switch (e) {
  56. case 0:
  57. // MtaH5.clickStat("heyi");
  58. // window.location.replace("homepage");
  59. this.$router.push("homepage");
  60. break;
  61. case 1:
  62. // MtaH5.clickStat("hequan");
  63. // window.location.replace("product");
  64. this.$router.push("product");
  65. break;
  66. case 2:
  67. this.$router.push("deliver");
  68. break;
  69. case 3:
  70. this.$router.push("customerprofile");
  71. break;
  72. }
  73. },
  74. // 获取当前连接
  75. watchTab() {
  76. var url = this.$route.path;
  77. console.log("a", url);
  78. if (url.indexOf("homepage") != -1) {
  79. this.active = 0;
  80. } else if (url.indexOf("product") != -1) {
  81. this.active = 1;
  82. } else if (url.indexOf("deliver") != -1) {
  83. this.active = 2;
  84. } else if (url.indexOf("customerprofile") != -1) {
  85. this.active = 3;
  86. }
  87. else {
  88. this.active = -1;
  89. }
  90. }
  91. }
  92. };
  93. </script>
  94. <style lang="less" scoped>
  95. .van-tabbar-item__icon img {
  96. width: unset !important;
  97. }
  98. </style>

vant-ui组件调用Dialog弹窗异步关闭_一键写代码的博客-CSDN博客需求描述:需求描述:官方文档又是组件调用方式,又是函数调用方式。我就需要一个很简单的:点击操作弹窗显示后,我填写一个表单,表单校验通过后,再调用API接口,返回成功后,关闭弹窗。一个很简单的东西,element-ui用的很方便,在这里就懵比了,刚开始做的,弹窗关闭了,才返回异步接口调用的结果。网速慢点,用起来真的很不好。正确的解决方式一: <van-dialog v-model="showDialog" title="提示" show-cancehttps://blog.csdn.net/qq_42991509/article/details/106049422

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/76922
推荐阅读
相关标签
  

闽ICP备14008679号