uni-app开发中的各类问题处理

一、关于自定义导航栏中的刘海屏适配问题:css

官方提供了一个CSS变量能够直接引用:html

var(--status-bar-height)后端

该变量自动匹配设备平台状态栏高度api

此变量能够用calc() 加上其余单位数值来使用缓存

具体参数和说明:官方使用自定义导航栏注意事项app

 

二、swiper中高度没法自适应时,采用动态获取节点赋值给外层swiper组件ui

uni.createSelectorQuery()后加.in(this)能够防止app端出错

 

<swiper :indicator-dots="true" :style="{height:listHeight+'px'}" :autoplay="false" :interval="3000" :duration="1000"></swiper>
  var _self;
    export default {
        data() {
            return {
                listHeight:215
            }
        },
        onLoad() {
            _self=this;
            _self.getEleHeight('.swiper-item');
        },
        onShow() {
            
        },
        methods: {
            getEleHeight(list){
                let info = uni.createSelectorQuery().in(_self).select(list);
              info.boundingClientRect(function(data) { //data - 各类参数
                  if(data != null){
                        _self.listHeight = data.height;
                    }else{
                        setTimeout(function(){
                            _self.getEleHeight('.swiper-item');
                        },300)
                    }
              }).exec()
            }
            
        }
    }

 三、横向scroll-view随子元素宽度自适应this

      关键在于给scroll-view的直接下一层view设置以下css:url

  width:auto;spa

  display: inline-block;

  white-space: nowrap;

                <scroll-view scroll-x="true" class="scroll_box">
                    <view class="list">
                        <view class="item" v-for="(item,index) of 4" :key="index">
                           
                        </view>
                    </view>
                </scroll-view>

 

.scroll_box{
    width: 100%;
    height: auto;
}

.list{
    width: auto;
    height: 100upx;
    display: inline-block;
    white-space: nowrap;
}

.item{
    width:320upx;
    display: inline-block;
    height: 100%;
}

 四、部分组件向上滑动超出屏幕时固定在顶部,仿饿了么吸顶

给该组件设置css定位元素position的值为sticky,能够结合top和left值来调节位置。

五、关于tabbar的一些状况

建议使用配置的tabbar,自定义的view没有缓存机制。

原生tabbar其实不少功能,参考读完如下知识点能实现大部分需求:

tabbar文档API方法:https://uniapp.dcloud.io/api/ui/tabbar

tabbar官网详解:https://uniapp.dcloud.io/collocation/pages?id=tabbar

六、保存图片到本地

真机亲测至少安卓有用

                uni.showModal({
                    title: '提示',
                    content: '肯定保存到相册吗',
                    success: function (res) {
                        if (res.confirm) {
                            
                            uni.downloadFile({
                                    url: _self.ewmImg,//图片地址
                                    success: (res) =>{
                                        if (res.statusCode === 200){
                                            uni.saveImageToPhotosAlbum({
                                                filePath: res.tempFilePath,
                                                success: function() {
                                                    uni.showToast({
                                                        title: "保存成功",
                                                        icon: "none"
                                                    });
                                                },
                                                fail: function() {
                                                    uni.showToast({
                                                        title: "保存失败",
                                                        icon: "none"
                                                    });
                                                }
                                            });
                                        } 
                                    }
                                })
                            
                            
                        } else if (res.cancel) {
                            
                        }
                    }
                });

 

 七、部分经常使用功能参考地址以下

  登陆和图片批量上传可借鉴下方连接

  uni-app 先后端实战课 - 《悦读》:http://www.hcoder.net/tutorials/info_1371.html

相关文章
相关标签/搜索