HBuilderX

HBuilderX

极客开发工具
uni-app

uni-app

开发一次,多端覆盖
uniCloud

uniCloud

云开发平台
HTML5+

HTML5+

增强HTML5的功能体验
MUI

MUI

上万Star的前端框架

【uniapp开发(结合vue2)】想使用uniapp扩展组件,却遇到Cannot find module '@dcloudio/uni-ui/lib/uni-***/uni-***.vue'

想使用uniapp扩展组件(npm安装+easycom配置),却遇到Cannot find module '@dcloudio/uni-ui/lib/uni-/uni-.vue',不能找到某模块

为了实现一些功能,借用了一些开源UI框架,PC端app模拟器测试时,好好地;而真机测试时,令人唏嘘不已。哎~难受~还是瞅瞅扩展组件吧~

下面跟大家分享一下,npm安装+easycom配置,安装uniapp扩展组件是的一个注意点。(本次分享,也是自己的笔记记录,分享有点长,可以认真看完也可以选择阅读,各位道友请自便)
【分享重点:主要是easycom,本着优化性能的原则的设计,没想到有点小瑕疵,解决这个小瑕疵】
npm安装uniapp扩展组件,根据官方安装介绍步骤正常进行,如下(更小的细节,像使用限制版本等,见官文):

1、根目录新建并配置 vue.config.js文件

// vue.config.js  
module.exports = {  
        transpileDependencies:['@dcloudio/uni-ui']  
}

2、准备 sass

// 安装 sass  
npm i sass -D   或   yarn add sass -D   
// 安装 sass-loader  
npm i sass-loader@10.1.1 -D   或   yarn add sass-loader@10.1.1 -D  
(安装时可以不指定版本号)

3、安装 uni-ui

npm i @dcloudio/uni-ui   或   yarn add @dcloudio/uni-ui

4、配置easycom(最关键的一步,也是找不到模块组件的问题所在)

//官方建议这么配置  
// pages.json  
{  
    "easycom": {  
        "autoscan": true,  
        "custom": {  
            // uni-ui 规则如下配置  
            "^uni-(.*)": "@dcloudio/uni-ui/lib/uni-$1/uni-$1.vue"  
        }  
    },  

    // 其他内容  
    pages:[  
        // ...  
    ]  
}

按理说,配置完之后就可以正常使用扩展组件了,但控制台出现了最不想见到的红色:Cannot find module........
其实easycom配置的规范样式并没有错,更深入的仔细看会发现安装的node模块下@dcloudio/uni-ui中并没有lib目录,所以找不到模块是正常的。

顺藤摸瓜,根据自己的模块目录自己将目录配置完整,就可以正常用扩展组件了。
我顺着模块目录,更改后的配置如下:

"easycom": {  
            "autoscan": true,  
            "custom": {  
                "^uni-(.*)": "@dcloudio/uni-ui/uni_modules/uni-$1/components/uni-$1/uni-$1.vue"  
            }  
        },

还有一个注意点,还要提醒初次配置扩展组件的道友注意,每次配置完easycom,需要重启项目或HBuilder,配置才会生效。
分享结束。

继续阅读 »

想使用uniapp扩展组件(npm安装+easycom配置),却遇到Cannot find module '@dcloudio/uni-ui/lib/uni-/uni-.vue',不能找到某模块

为了实现一些功能,借用了一些开源UI框架,PC端app模拟器测试时,好好地;而真机测试时,令人唏嘘不已。哎~难受~还是瞅瞅扩展组件吧~

下面跟大家分享一下,npm安装+easycom配置,安装uniapp扩展组件是的一个注意点。(本次分享,也是自己的笔记记录,分享有点长,可以认真看完也可以选择阅读,各位道友请自便)
【分享重点:主要是easycom,本着优化性能的原则的设计,没想到有点小瑕疵,解决这个小瑕疵】
npm安装uniapp扩展组件,根据官方安装介绍步骤正常进行,如下(更小的细节,像使用限制版本等,见官文):

1、根目录新建并配置 vue.config.js文件

// vue.config.js  
module.exports = {  
        transpileDependencies:['@dcloudio/uni-ui']  
}

2、准备 sass

// 安装 sass  
npm i sass -D   或   yarn add sass -D   
// 安装 sass-loader  
npm i sass-loader@10.1.1 -D   或   yarn add sass-loader@10.1.1 -D  
(安装时可以不指定版本号)

3、安装 uni-ui

npm i @dcloudio/uni-ui   或   yarn add @dcloudio/uni-ui

4、配置easycom(最关键的一步,也是找不到模块组件的问题所在)

//官方建议这么配置  
// pages.json  
{  
    "easycom": {  
        "autoscan": true,  
        "custom": {  
            // uni-ui 规则如下配置  
            "^uni-(.*)": "@dcloudio/uni-ui/lib/uni-$1/uni-$1.vue"  
        }  
    },  

    // 其他内容  
    pages:[  
        // ...  
    ]  
}

按理说,配置完之后就可以正常使用扩展组件了,但控制台出现了最不想见到的红色:Cannot find module........
其实easycom配置的规范样式并没有错,更深入的仔细看会发现安装的node模块下@dcloudio/uni-ui中并没有lib目录,所以找不到模块是正常的。

顺藤摸瓜,根据自己的模块目录自己将目录配置完整,就可以正常用扩展组件了。
我顺着模块目录,更改后的配置如下:

"easycom": {  
            "autoscan": true,  
            "custom": {  
                "^uni-(.*)": "@dcloudio/uni-ui/uni_modules/uni-$1/components/uni-$1/uni-$1.vue"  
            }  
        },

还有一个注意点,还要提醒初次配置扩展组件的道友注意,每次配置完easycom,需要重启项目或HBuilder,配置才会生效。
分享结束。

收起阅读 »

希望HBuilderX控制台增加两个功能,搜索和清空按钮

HBuilderX

希望HBuilderX控制台增加两个功能,搜索和清空按钮。谢谢。

希望HBuilderX控制台增加两个功能,搜索和清空按钮。谢谢。

温州微凌客科技有限公司 全栈经验,全职接单

外包

16年成立,近10年开发经验。写过各类uniapp+tp 项目 求接单或外包

16年成立,近10年开发经验。写过各类uniapp+tp 项目 求接单或外包

关于jql如何开启事务

uniCloud

接触云开发不久,想蹭蹭免费的阿里云服务器,某些新增编辑业务想使用开启事务,但最后实现不出来发现,好像事务只能用于云函数,但是又不打算使用云函数(阿里云函数有限制),也懒得搞单路由云函数,所以想用jql来实现


无意中发现action好像可以实现,结果试了一下发现只能回滚当前加了action这条的操作。
需求:用户有多个收货地址,但是默认地址只能有一个;

// 用户设置默认收货地址  
db.action('test').collection('user-address').doc(e._id).update({is_default: true })

action-test如下


结果发现,直接进行rollback操作了,上图设置旧默认地址的操作一直没法正常回滚。
所以实在不明白action中的事务操作有什么作用,难道jql是真的开不了事务吗

----------- 补充 -------------

经过测试发现了问题所在,开启了事务之后,得使用transaction来替代db才能将该次请求加入到事务中

const db = uniCloud.database()  
state.transaction = await db.startTransaction()  
// 该次操作加入事务中,由事务管理  
state.transaction.collection('user-address').doc(defaultAddr.data[0]._id).update({is_default: false})  
// 该次操作不加入事务  
db.collection('user-address').doc(defaultAddr.data[0]._id).update({is_default: false})

最终测试,action和云函数中是可以加入事务的,但是jql中是无法开启的,原因可能如下

// 云函数中使用db有两种创建方式  
const db = uniCloud.database()    // 不支持jql语法  
const dbJql = uniCloud.databaseForJQL()    // 支持jql语法  
// clientDB中使用db  
const db = uniCloud.database()    // 支持jql语法

可能因为在clientDB中创建的 db 默认就是 JQL 吧,调用transaction.collection会提示没有collection方法,就像在云函数中使用dbJql去创建transaction一样。所以想分开封装请求而不经过云函数,可能目前还不行。

继续阅读 »

接触云开发不久,想蹭蹭免费的阿里云服务器,某些新增编辑业务想使用开启事务,但最后实现不出来发现,好像事务只能用于云函数,但是又不打算使用云函数(阿里云函数有限制),也懒得搞单路由云函数,所以想用jql来实现


无意中发现action好像可以实现,结果试了一下发现只能回滚当前加了action这条的操作。
需求:用户有多个收货地址,但是默认地址只能有一个;

// 用户设置默认收货地址  
db.action('test').collection('user-address').doc(e._id).update({is_default: true })

action-test如下


结果发现,直接进行rollback操作了,上图设置旧默认地址的操作一直没法正常回滚。
所以实在不明白action中的事务操作有什么作用,难道jql是真的开不了事务吗

----------- 补充 -------------

经过测试发现了问题所在,开启了事务之后,得使用transaction来替代db才能将该次请求加入到事务中

const db = uniCloud.database()  
state.transaction = await db.startTransaction()  
// 该次操作加入事务中,由事务管理  
state.transaction.collection('user-address').doc(defaultAddr.data[0]._id).update({is_default: false})  
// 该次操作不加入事务  
db.collection('user-address').doc(defaultAddr.data[0]._id).update({is_default: false})

最终测试,action和云函数中是可以加入事务的,但是jql中是无法开启的,原因可能如下

// 云函数中使用db有两种创建方式  
const db = uniCloud.database()    // 不支持jql语法  
const dbJql = uniCloud.databaseForJQL()    // 支持jql语法  
// clientDB中使用db  
const db = uniCloud.database()    // 支持jql语法

可能因为在clientDB中创建的 db 默认就是 JQL 吧,调用transaction.collection会提示没有collection方法,就像在云函数中使用dbJql去创建transaction一样。所以想分开封装请求而不经过云函数,可能目前还不行。

收起阅读 »

uni-app安卓端生成桌面快捷应用

快捷方式

在A页面 点击按钮创建应用

createShortcut(){  
                const routes = getCurrentPages();  
                let curRoute = routes[routes.length - 1].route  
                // console.log(curRoute);  
                plus.navigator.createShortcut({  
                        name: "我是第一个",  
                        icon: '/static/c1.png',  
                        extra:{  
                            path:curRoute,// 应用地址  
                            title:'第一个快捷方式'  
                        },  
                        // toast: "已创建快捷方式到桌面"  
                    }, function(e){  
                        console.log("A=",e); // {"sure":false}  
                    }, function(e){  
                    console.log("B=",e);  
                    console.log("C=",e.message);  
                });

在app.vue页面进行读取快捷应用地址

onShow: function() {  
        console.log('App Show');  
        let main = plus.android.runtimeMainActivity();  
        const Intent = plus.android.importClass('android.content.Intent');  
        const intent = main.getIntent();  
        let path = intent.getStringExtra('path'); // list 里面的 path  
        if (path === null) return; //path为null或者未登录,直接return  
        //使用 $nextTick 延时跳转,避免在 tabBar 页面出现 BUG  
        this.$nextTick(function() {  
            //快捷方式执行逻辑(跳转页面的话,只需要在此处写上跳转逻辑)  
            uni.navigateTo({  
                url: '/' + path  
            });  
        });  
        //移除跳转路径,避免后续打开默认为快捷方式唤醒  
        intent.removeExtra('path');  
    },
继续阅读 »

在A页面 点击按钮创建应用

createShortcut(){  
                const routes = getCurrentPages();  
                let curRoute = routes[routes.length - 1].route  
                // console.log(curRoute);  
                plus.navigator.createShortcut({  
                        name: "我是第一个",  
                        icon: '/static/c1.png',  
                        extra:{  
                            path:curRoute,// 应用地址  
                            title:'第一个快捷方式'  
                        },  
                        // toast: "已创建快捷方式到桌面"  
                    }, function(e){  
                        console.log("A=",e); // {"sure":false}  
                    }, function(e){  
                    console.log("B=",e);  
                    console.log("C=",e.message);  
                });

在app.vue页面进行读取快捷应用地址

onShow: function() {  
        console.log('App Show');  
        let main = plus.android.runtimeMainActivity();  
        const Intent = plus.android.importClass('android.content.Intent');  
        const intent = main.getIntent();  
        let path = intent.getStringExtra('path'); // list 里面的 path  
        if (path === null) return; //path为null或者未登录,直接return  
        //使用 $nextTick 延时跳转,避免在 tabBar 页面出现 BUG  
        this.$nextTick(function() {  
            //快捷方式执行逻辑(跳转页面的话,只需要在此处写上跳转逻辑)  
            uni.navigateTo({  
                url: '/' + path  
            });  
        });  
        //移除跳转路径,避免后续打开默认为快捷方式唤醒  
        intent.removeExtra('path');  
    },
收起阅读 »

FFmpeg升级增强完整版、跟官方video不冲突、视频编辑 音频编辑 视频压缩 合成 裁剪 图片 水印 gif 转码...(ios、andorid)

FFmpeg升级增强完整版、跟官方video不冲突、视频编辑 音频编辑 视频压缩 合成 裁剪 图片 水印 gif 转码...(ios、andorid):https://ext.dcloud.net.cn/plugin?id=8690

继续阅读 »

FFmpeg升级增强完整版、跟官方video不冲突、视频编辑 音频编辑 视频压缩 合成 裁剪 图片 水印 gif 转码...(ios、andorid):https://ext.dcloud.net.cn/plugin?id=8690

收起阅读 »

解决barcode识别超长内容无法识别、识别错误内容数字

Barcode 二维码 二维码扫描

已通过zxing的原生插件解决 兼容安卓7.0-12
遇到相同问题的私聊我

已通过zxing的原生插件解决 兼容安卓7.0-12
遇到相同问题的私聊我

今天阴历多少?你用过离线可用的pwa应用吗?

日历

在生活中,我们往往想要知道,今天阴历是多少?农历是多少?天干纪年是多少?甚至想要知道波斯历是多少?伊斯兰历是多少?

同是我们的手机和电脑不一定,24小时有网络,那怎么解决这些问题?

无意中,我找到了这款PWA应用,手机、浏览器都可以用,甚至只要访问一次,离线也可用。他提供:阴历、农历、波斯历、伊斯兰历显示。占用空间也不过500K,现分享给大家,希望大家喜欢:
https://pwa.ywz1.com/rili/index.html#/
提示:这是用uniapp开发的哦,大家赶紧去用uniapp开发pwa吧,也很方便

继续阅读 »

在生活中,我们往往想要知道,今天阴历是多少?农历是多少?天干纪年是多少?甚至想要知道波斯历是多少?伊斯兰历是多少?

同是我们的手机和电脑不一定,24小时有网络,那怎么解决这些问题?

无意中,我找到了这款PWA应用,手机、浏览器都可以用,甚至只要访问一次,离线也可用。他提供:阴历、农历、波斯历、伊斯兰历显示。占用空间也不过500K,现分享给大家,希望大家喜欢:
https://pwa.ywz1.com/rili/index.html#/
提示:这是用uniapp开发的哦,大家赶紧去用uniapp开发pwa吧,也很方便

收起阅读 »

查询和获取权限为一体的插件、获取权限状态、请求权限授权、AppTracking、通知权限、权限一体化

查询和获取权限为一体的插件、获取权限状态、请求权限授权、AppTracking、通知权限、权限一体化:https://ext.dcloud.net.cn/plugin?id=8674

继续阅读 »

查询和获取权限为一体的插件、获取权限状态、请求权限授权、AppTracking、通知权限、权限一体化:https://ext.dcloud.net.cn/plugin?id=8674

收起阅读 »

uniapp 实现nvue模拟顶部双吸顶+左右滑动切换选项卡(适用于视频播放详情,支持Android、iOS)

场景说明
在app中用nvue实现视频播放页面,页面分为顶部视频区、课程标题区、tab选项卡区
需求1:用自定义黑色view占位标题栏区域,自定义状态栏占位区和视频区固定在顶部;
需求2:课程标题区随着页面上下滑动而滚动
需求3:tab选项卡区滑动到视频区底部时,自动吸顶
需求4:tab的每个子选项卡滚动高度各自独立
需求5:隐藏页面滚动条,仅显示tab选项卡区滚动条

index.nvue

<template>  

    <!-- :show-scrollbar="false"  不显示页面的滚动条 -->  
    <!-- :bounce="true" 开启iOS回弹效果 -->  
    <list id="page" class="page" :bounce="true" :show-scrollbar="false" isSwiperList="true">  

        <!-- 课程封面/视频播放器 -->  
        <!-- 固定吸在顶部 -->  
        <header>  
            <view id="head">  
                <!-- 黑色状态栏 -->  
                <view class="status-bar" :style="'height:' + statusHeight + 'px'">  
                </view>  
                <!-- 封面区/视频区 -->  
                <view class="cover-box">  

                    <!--  
                        课程封面/视频播放器区  
                        tab选项卡总高度:{{pageHeight}}  
                        tab选项卡吸顶高度:{{_headHeight}}(iOS端生效)   
                    -->  

                    <video title="uniapp nvue顶部双吸顶+左右滑动切换选项卡" src="https://api.dogecloud.com/player/get.mp4?vcode=5ac682e6f8231991&userId=17&ext=.mp4" objectFit="fill"   
                    poster="https://i.loli.net/2019/06/06/5cf8c5d9c57b510947.png" style="width:750rpx;height: 200px;"></video>  

                </view>  
            </view>  
        </header>  

        <!-- 课程标题 -->  
        <!-- 不固定,随着竖向滚动条滑动 -->  
        <cell>  
            <view id="intro-box" class="intro-box">  
                课程标题区  
            </view>  
        </cell>  

        <!-- 可横向滑动切换选项卡 -->  
        <!-- 滑到封面区/视频区底部位置,自动吸顶 -->  
        <cell>  
            <view class="tabs" :style="'height:' + pageHeight + 'px'">  
                <scroll-view ref="tabbar1" id="tab-bar" class="tab-bar" :scroll="false" :scroll-x="false"  
                    :show-scrollbar="false" :scroll-into-view="scrollInto">  
                    <view style="flex-direction: column;">  
                        <view style="flex-direction: row;">  
                            <view class="uni-tab-item" id="tab0" ref="tabitem0" data-id="0" data-current="0"  
                                @click="ontabtap">  
                                <text class="uni-tab-item-title"  
                                    :class="tabIndex==0 ? 'uni-tab-item-title-active' : ''">详情</text>  
                            </view>  
                            <view class="uni-tab-item" id="tab1" ref="tabitem1" data-id="1" data-current="1"  
                                @click="ontabtap">  
                                <text class="uni-tab-item-title"  
                                    :class="tabIndex==1 ? 'uni-tab-item-title-active' : ''">目录</text>  
                            </view>  
                            <view class="uni-tab-item" id="tab2" ref="tabitem2" data-id="2" data-current="2"  
                                @click="ontabtap">  
                                <text class="uni-tab-item-title"  
                                    :class="tabIndex==2 ? 'uni-tab-item-title-active' : ''">评论</text>  
                            </view>  
                            <view class="uni-tab-item" id="tab3" ref="tabitem3" data-id="3" data-current="3"  
                                @click="ontabtap">  
                                <text class="uni-tab-item-title"  
                                    :class="tabIndex==3 ? 'uni-tab-item-title-active' : ''">资料</text>  
                            </view>  
                        </view>  
                        <view class="scroll-view-indicator">  
                            <view ref="underline" class="scroll-view-underline"  
                                :class="isTap ? 'scroll-view-animation':''"  
                                :style="{left: indicatorLineLeft + 'px', width: indicatorLineWidth + 'px'}"></view>  
                        </view>  
                    </view>  
                </scroll-view>  
                <view class="tab-bar-line"></view>  
                <swiper class="tab-view" ref="swiper1" id="tab-bar-view" :current="tabIndex" :duration="300"  
                    @change="onswiperchange" @transition="onswiperscroll" @animationfinish="animationfinish"  
                    @onAnimationEnd="animationfinish">  
                    <swiper-item class="swiper-item">  
                        <!-- 详情 -->  
                        <view class="uni-swiper-page">  
                            <list ref="list0" class="list" :offset-accuracy="5" :bounce="true" isSwiperList="true">  
                                <cell @click="onclick">  
                                    课程简介内容  
                                </cell>  
                                <cell class="loading"></cell>  
                            </list>  
                        </view>  
                    </swiper-item>  
                    <swiper-item class="swiper-item">  
                        <!-- 目录 -->  
                        <view class="uni-swiper-page">  
                            <list ref="list1" class="list" :offset-accuracy="5" :bounce="true" isSwiperList="true">  
                                <cell @click="onclick">  
                                    <view class="list-item" v-for="(item,index) in [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49]">  
                                        <text>章节{{item}}</text>  
                                    </view>  
                                </cell>  
                                <cell class="loading"></cell>  
                            </list>  
                        </view>  
                    </swiper-item>  
                    <swiper-item class="swiper-item">  
                        <!-- 评论 -->  
                        <view class="uni-swiper-page">  
                            <list ref="list2" class="list" :offset-accuracy="5" :bounce="true" isSwiperList="true">  
                                <cell @click="onclick">  
                                    <view class="list-item" v-for="(item,index) in [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49]">  
                                        <text>评论{{item}}</text>  
                                    </view>  
                                </cell>  
                                <cell class="loading"></cell>  
                            </list>  
                        </view>  
                    </swiper-item>  
                    <swiper-item class="swiper-item">  
                        <!-- 资料 -->  
                        <view class="uni-swiper-page">  
                            <list ref="list3" class="list" :offset-accuracy="5" :bounce="true" isSwiperList="true">  
                                <cell @click="onclick">  
                                    <view class="list-item" v-for="(item,index) in [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49]">  
                                        <text>资料{{item}}</text>  
                                    </view>  
                                </cell>  
                                <cell class="loading"></cell>  
                            </list>  
                        </view>  
                    </swiper-item>  
                </swiper>  
            </view>  
        </cell>  
    </list>  
</template>  

<script>  
    // #ifdef APP-PLUS  
    const dom = weex.requireModule('dom');  
    // #endif  
    // 缓存每页最多  
    const MAX_CACHE_DATA = 100;  
    // 缓存页签数量  
    const MAX_CACHE_PAGE = 3;  
    const TAB_PRELOAD_OFFSET = 1;  
    export default {  
        data() {  
            return {  
                tabIndex: 0,  
                cacheTab: [],  
                scrollInto: "",  
                indicatorLineLeft: 0,  
                indicatorLineWidth: 0,  
                isTap: false,  
                showTitleView: true,  
                statusHeight: 44,  
                pageHeight: 300,  
                refreshing: false,  
                refreshText: "",  
                refreshFlag: false  
            }  
        },  
        onLoad() {  

        },  
        onReady() {  
            let inf = uni.getSystemInfoSync();  
            this.statusHeight = inf.statusBarHeight; // 状态栏高度  
            this.pageHeight = inf.windowHeight - this.statusHeight - 200; // 页面高度  
            this._lastTabIndex = 0;  
            this.swiperWidth = 0;  
            this.tabbarWidth = 0;  
            this.tabListSize = {};  
            this._touchTabIndex = 0;  
            this._headHeight = 100;  
            this.selectorQuery();  

            // #ifdef APP-PLUS  
            plus.navigator.setStatusBarStyle("light"); //白色  
            // #endif  
        },  
        methods: {  

            setScrollRef(index, height) {  
                // Android不支持setSpecialEffects , 仅iOS机型生效  
                if (this.$refs['list' + index].setSpecialEffects) {  
                    this.$refs['list' + index].setSpecialEffects({  
                        id: "page",  
                        headerHeight: height //设置iOS端Tabs距离顶部的吸顶距离  
                    });  
                }  
            },  
            onclick(e) {  
                console.log("onclick");  
            },  
            loadData() {  
                // 首次激活时被调用  
            },  
            clear() {  
                // 释放数据时被调用,参考 swiper-list 缓存配置  
            },  

            ontap1(e) {  
                console.log("ontap1", e);  
            },  
            ontabtap(e) {  
                let index = e.target.dataset.current || e.currentTarget.dataset.current;  
                //let offsetIndex = this._touchTabIndex = Math.abs(index - this._lastTabIndex) > 1;  
                // #ifdef APP-PLUS || H5 || MP-WEIXIN || MP-QQ  
                this.isTap = true;  
                var currentSize = this.tabListSize[index];  
                this.updateIndicator(currentSize.left, currentSize.width);  
                this._touchTabIndex = index;  
                // #endif  
                this.switchTab(index);  
            },  
            onswiperchange(e) {  
                // 注意:百度小程序会触发2次  
                // #ifndef APP-PLUS || H5 || MP-WEIXIN || MP-QQ  
                let index = e.target.current || e.detail.current;  
                this.switchTab(index);  
                // #endif  
            },  
            onswiperscroll(e) {  
                if (this.isTap) {  
                    return;  
                }  
                var offsetX = e.detail.dx;  
                var preloadIndex = this._lastTabIndex;  
                if (offsetX > TAB_PRELOAD_OFFSET) {  
                    preloadIndex++;  
                } else if (offsetX < -TAB_PRELOAD_OFFSET) {  
                    preloadIndex--;  
                }  
                if (preloadIndex === this._lastTabIndex || preloadIndex < 0 || preloadIndex > 4 - 1) {  
                    return;  
                }  
                // if (this.pageList[preloadIndex].dataList.length === 0) {  
                //  this.loadTabData(preloadIndex);  
                // }  
                // #ifdef APP-PLUS || H5 || MP-WEIXIN || MP-QQ  
                var percentage = Math.abs(this.swiperWidth / offsetX);  
                var currentSize = this.tabListSize[this._lastTabIndex];  
                var preloadSize = this.tabListSize[preloadIndex];  
                var lineL = currentSize.left + (preloadSize.left - currentSize.left) / percentage;  
                var lineW = currentSize.width + (preloadSize.width - currentSize.width) / percentage;  
                this.updateIndicator(lineL, lineW);  
                // #endif  
            },  
            animationfinish(e) {  
                // #ifdef APP-PLUS || H5 || MP-WEIXIN || MP-QQ  
                let index = e.detail.current;  
                if (this._touchTabIndex === index) {  
                    this.isTap = false;  
                }  
                this._lastTabIndex = index;  
                this.switchTab(index);  
                this.updateIndicator(this.tabListSize[index].left, this.tabListSize[index].width);  
                // #endif  
            },  
            selectorQuery() {  
                // #ifdef APP-NVUE  
                //      uni.createSelectorQuery().in(this).select('#head').boundingClientRect().exec(rect => {  
                // // 获取封面区高度  
                // this._headHeight = rect[0].height;  
                //      });  
                uni.createSelectorQuery().in(this).select('#intro-box').boundingClientRect().exec(rect => {  
                    // 获取课程简介区的位置,设为iOS端Tabs距离顶部的吸顶距离  
                    this._headHeight = rect[0].height - 1;  
                    console.log('3 introHeight', this._headHeight);  
                });  
                // 查询 tabbar 宽度  
                uni.createSelectorQuery().in(this).select('#tab-bar').boundingClientRect().exec(rect => {  
                    this.tabbarWidth = rect[0].width;  
                });  
                // 查询 tabview 宽度  
                uni.createSelectorQuery().in(this).select('#tab-bar-view').boundingClientRect().exec(rect => {  
                    this.swiperWidth = rect[0].width;  
                });  
                // 因 nvue 暂不支持 class 查询  
                var queryTabSize = uni.createSelectorQuery().in(this);  
                queryTabSize.select('#tab0').boundingClientRect();  
                queryTabSize.select('#tab1').boundingClientRect();  
                queryTabSize.select('#tab2').boundingClientRect();  
                queryTabSize.select('#tab3').boundingClientRect();  
                queryTabSize.exec(rects => {  
                    rects.forEach((rect) => {  
                        this.tabListSize[rect.dataset.id] = rect;  
                    })  
                    this.updateIndicator(this.tabListSize[this.tabIndex].left, this.tabListSize[this.tabIndex]  
                        .width);  
                    this.switchTab(this.tabIndex);  
                });  
                // #endif  
                // #ifdef MP-WEIXIN || H5 || MP-QQ  
                uni.createSelectorQuery().in(this).select('.tab-view').fields({  
                    dataset: true,  
                    size: true,  
                }, (res) => {  
                    this.swiperWidth = res.width;  
                }).exec();  
                uni.createSelectorQuery().in(this).selectAll('.uni-tab-item').boundingClientRect((rects) => {  
                    rects.forEach((rect) => {  
                        this.tabListSize[rect.dataset.id] = rect;  
                    })  
                    this.updateIndicator(this.tabListSize[this.tabIndex].left, this.tabListSize[this.tabIndex]  
                        .width);  
                }).exec();  
                // #endif  
            },  
            updateIndicator(left, width) {  
                this.indicatorLineLeft = left;  
                this.indicatorLineWidth = width;  
            },  
            switchTab(index) {  
                // if (this.pageList[index].dataList.length === 0) {  
                //  this.loadTabData(index);  
                // }  
                this.setScrollRef(index,this._headHeight);  
                // if (this.tabIndex === index) {  
                //  return;  
                // }  
                // // 缓存 tabId  
                // if (this.pageList[this.tabIndex].dataList.length > MAX_CACHE_DATA) {  
                //  let isExist = this.cacheTab.indexOf(this.tabIndex);  
                //  if (isExist < 0) {  
                //      this.cacheTab.push(this.tabIndex);  
                //  }  
                // }  
                this.tabIndex = index;  
                // #ifdef APP-NVUE  
                this.scrollTabTo(index);  
                // #endif  
                // #ifndef APP-NVUE  
                this.scrollInto = "tab" + index;  
                // #endif  
                // 释放 tabId  
                // if (this.cacheTab.length > MAX_CACHE_PAGE) {  
                //  let cacheIndex = this.cacheTab[0];  
                //  this.clearTabData(cacheIndex);  
                //  this.cacheTab.splice(0, 1);  
                // }  
            },  
            scrollTabTo(index) {  
                const el = this.$refs['tabitem' + index][0];  
                let offset = 0;  
                // TODO fix ios offset  
                if (index > 0) {  
                    offset = this.tabbarWidth / 2 - this.tabListSize[index].width / 2;  
                    if (this.tabListSize[index].right < this.tabbarWidth / 2) {  
                        offset = this.tabListSize[0].width;  
                    }  
                }  
                dom.scrollToElement(el, {  
                    offset: -offset  
                });  
            },  
            loadTabData(index) {  
                // this.pageList[index].loadData();  
            },  
            clearTabData(index) {  
                // this.pageList[index].clear();  
            },  
            onrefresh(e) {  
                // this.refreshing = true;  
                // this.refreshText = "刷新中...";  
                // setTimeout(() => {  
                //  this.refreshing = false;  
                //  this.refreshFlag = false;  
                //  this.refreshText = "已刷新";  
                // }, 2000)  
            },  
            onpullingdown(e) {  
                if (this.refreshing) {  
                    return;  
                }  
                this.pulling = false;  
                if (Math.abs(e.pullingDistance) > Math.abs(e.viewHeight)) {  
                    this.refreshFlag = true;  
                    this.refreshText = "释放立即刷新";  
                } else {  
                    this.refreshFlag = false;  
                    this.refreshText = "下拉可以刷新";  
                }  
            }  
        }  
    }  
</script>  

<style>  
    /* #ifndef APP-PLUS */  
    page {  
        width: 100%;  
        min-height: 100%;  
        display: flex;  
    }  

    /* #endif */  
    .page {  
        flex: 1;  
    }  

    .cover-box {  
        width: 750rpx;  
        height: 200px;  
        flex-direction: row;  
        align-items: center;  
        justify-content: center;  
        background-color: #ffffff;  
    }  

    .status-bar {  
        height: 44px;  
        color: #ffffff;  
        background-color: #000000;  
    }  

    .intro-box {  
        height: 160px;  
        flex-direction: row;  
        align-items: center;  
        justify-content: center;  
        /* background-color: #f4f4f4; */  
    }  

    .flexible-view {  
        background-color: #f823ff;  
    }  

    .page-head {  
        height: 200px;  
        flex-direction: column;  
        align-items: center;  
        justify-content: center;  
        background-color: red;  
    }  

    .tabs {  
        flex-direction: column;  
        overflow: hidden;  
        background-color: #ffffff;  
        /* #ifdef MP-ALIPAY || MP-BAIDU */  
        height: 100vh;  
        /* #endif */  
    }  

    .tab-bar {  
        width: 750upx;  
        height: 84upx;  
        flex-direction: row;  
        /* #ifndef APP-PLUS */  
        white-space: nowrap;  
        /* #endif */  
    }  

    /* #ifndef APP-NVUE */  
    .tab-bar ::-webkit-scrollbar {  
        display: none;  
        width: 0 !important;  
        height: 0 !important;  
        -webkit-appearance: none;  
        background: transparent;  
    }  

    /* #endif */  
    .scroll-view-indicator {  
        position: relative;  
        height: 2px;  
        background-color: transparent;  
    }  

    .scroll-view-underline {  
        position: absolute;  
        top: 0;  
        bottom: 0;  
        width: 0;  
        background-color: #007AFF;  
    }  

    .scroll-view-animation {  
        transition-duration: 0.2s;  
        transition-property: left;  
    }  

    .tab-bar-line {  
        height: 1upx;  
        background-color: #cccccc;  
    }  

    .tab-view {  
        flex: 1;  
    }  

    .uni-tab-item {  
        /* #ifndef APP-PLUS */  
        display: inline-block;  
        /* #endif */  
        flex-wrap: nowrap;  
        padding-left: 25px;  
        padding-right: 25px;  
    }  

    .uni-tab-item-title {  
        color: #555;  
        font-size: 30upx;  
        height: 80upx;  
        line-height: 80upx;  
        flex-wrap: nowrap;  
        /* #ifndef APP-PLUS */  
        white-space: nowrap;  
        /* #endif */  
    }  

    .uni-tab-item-title-active {  
        color: #007AFF;  
    }  

    .swiper-item {  
        flex: 1;  
        flex-direction: column;  
    }  

    .swiper-page {  
        flex: 1;  
        flex-direction: row;  
        position: absolute;  
        left: 0;  
        top: 0;  
        right: 0;  
        bottom: 0;  
    }  

    .refresh-view {  
        width: 750rpx;  
        height: 80px;  
        flex-direction: row;  
        align-items: center;  
        justify-content: center;  
    }  
</style>  

<style scoped>  
    .uni-swiper-page {  
        flex: 1;  
        position: absolute;  
        left: 0;  
        top: 0;  
        right: 0;  
        bottom: 0;  
    }  
    .list {  
        flex: 1;  
        background-color: #ebebeb;  
    }  
    .list-item {  
        margin-left: 12px;  
        margin-right: 12px;  
        margin-top: 12px;  
        padding: 20px;  
        background-color: #fff;  
        border-radius: 5px;  
    }  
    .loading {  
        height: 20px;  
    }  
</style>

pages.json


{  
    "pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages  
        {  
            "path": "pages/index/index",  
            "style": {  
                "navigationBarTitleText": "uni-app",  
                "navigationStyle": "custom"  
            }  
        }  
    ],  
    "globalStyle": {  
        "navigationBarTextStyle": "black",  
        "navigationBarTitleText": "uni-app",  
        "navigationBarBackgroundColor": "#F8F8F8",  
        "backgroundColor": "#F8F8F8"  
    }  
}
继续阅读 »

场景说明
在app中用nvue实现视频播放页面,页面分为顶部视频区、课程标题区、tab选项卡区
需求1:用自定义黑色view占位标题栏区域,自定义状态栏占位区和视频区固定在顶部;
需求2:课程标题区随着页面上下滑动而滚动
需求3:tab选项卡区滑动到视频区底部时,自动吸顶
需求4:tab的每个子选项卡滚动高度各自独立
需求5:隐藏页面滚动条,仅显示tab选项卡区滚动条

index.nvue

<template>  

    <!-- :show-scrollbar="false"  不显示页面的滚动条 -->  
    <!-- :bounce="true" 开启iOS回弹效果 -->  
    <list id="page" class="page" :bounce="true" :show-scrollbar="false" isSwiperList="true">  

        <!-- 课程封面/视频播放器 -->  
        <!-- 固定吸在顶部 -->  
        <header>  
            <view id="head">  
                <!-- 黑色状态栏 -->  
                <view class="status-bar" :style="'height:' + statusHeight + 'px'">  
                </view>  
                <!-- 封面区/视频区 -->  
                <view class="cover-box">  

                    <!--  
                        课程封面/视频播放器区  
                        tab选项卡总高度:{{pageHeight}}  
                        tab选项卡吸顶高度:{{_headHeight}}(iOS端生效)   
                    -->  

                    <video title="uniapp nvue顶部双吸顶+左右滑动切换选项卡" src="https://api.dogecloud.com/player/get.mp4?vcode=5ac682e6f8231991&userId=17&ext=.mp4" objectFit="fill"   
                    poster="https://i.loli.net/2019/06/06/5cf8c5d9c57b510947.png" style="width:750rpx;height: 200px;"></video>  

                </view>  
            </view>  
        </header>  

        <!-- 课程标题 -->  
        <!-- 不固定,随着竖向滚动条滑动 -->  
        <cell>  
            <view id="intro-box" class="intro-box">  
                课程标题区  
            </view>  
        </cell>  

        <!-- 可横向滑动切换选项卡 -->  
        <!-- 滑到封面区/视频区底部位置,自动吸顶 -->  
        <cell>  
            <view class="tabs" :style="'height:' + pageHeight + 'px'">  
                <scroll-view ref="tabbar1" id="tab-bar" class="tab-bar" :scroll="false" :scroll-x="false"  
                    :show-scrollbar="false" :scroll-into-view="scrollInto">  
                    <view style="flex-direction: column;">  
                        <view style="flex-direction: row;">  
                            <view class="uni-tab-item" id="tab0" ref="tabitem0" data-id="0" data-current="0"  
                                @click="ontabtap">  
                                <text class="uni-tab-item-title"  
                                    :class="tabIndex==0 ? 'uni-tab-item-title-active' : ''">详情</text>  
                            </view>  
                            <view class="uni-tab-item" id="tab1" ref="tabitem1" data-id="1" data-current="1"  
                                @click="ontabtap">  
                                <text class="uni-tab-item-title"  
                                    :class="tabIndex==1 ? 'uni-tab-item-title-active' : ''">目录</text>  
                            </view>  
                            <view class="uni-tab-item" id="tab2" ref="tabitem2" data-id="2" data-current="2"  
                                @click="ontabtap">  
                                <text class="uni-tab-item-title"  
                                    :class="tabIndex==2 ? 'uni-tab-item-title-active' : ''">评论</text>  
                            </view>  
                            <view class="uni-tab-item" id="tab3" ref="tabitem3" data-id="3" data-current="3"  
                                @click="ontabtap">  
                                <text class="uni-tab-item-title"  
                                    :class="tabIndex==3 ? 'uni-tab-item-title-active' : ''">资料</text>  
                            </view>  
                        </view>  
                        <view class="scroll-view-indicator">  
                            <view ref="underline" class="scroll-view-underline"  
                                :class="isTap ? 'scroll-view-animation':''"  
                                :style="{left: indicatorLineLeft + 'px', width: indicatorLineWidth + 'px'}"></view>  
                        </view>  
                    </view>  
                </scroll-view>  
                <view class="tab-bar-line"></view>  
                <swiper class="tab-view" ref="swiper1" id="tab-bar-view" :current="tabIndex" :duration="300"  
                    @change="onswiperchange" @transition="onswiperscroll" @animationfinish="animationfinish"  
                    @onAnimationEnd="animationfinish">  
                    <swiper-item class="swiper-item">  
                        <!-- 详情 -->  
                        <view class="uni-swiper-page">  
                            <list ref="list0" class="list" :offset-accuracy="5" :bounce="true" isSwiperList="true">  
                                <cell @click="onclick">  
                                    课程简介内容  
                                </cell>  
                                <cell class="loading"></cell>  
                            </list>  
                        </view>  
                    </swiper-item>  
                    <swiper-item class="swiper-item">  
                        <!-- 目录 -->  
                        <view class="uni-swiper-page">  
                            <list ref="list1" class="list" :offset-accuracy="5" :bounce="true" isSwiperList="true">  
                                <cell @click="onclick">  
                                    <view class="list-item" v-for="(item,index) in [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49]">  
                                        <text>章节{{item}}</text>  
                                    </view>  
                                </cell>  
                                <cell class="loading"></cell>  
                            </list>  
                        </view>  
                    </swiper-item>  
                    <swiper-item class="swiper-item">  
                        <!-- 评论 -->  
                        <view class="uni-swiper-page">  
                            <list ref="list2" class="list" :offset-accuracy="5" :bounce="true" isSwiperList="true">  
                                <cell @click="onclick">  
                                    <view class="list-item" v-for="(item,index) in [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49]">  
                                        <text>评论{{item}}</text>  
                                    </view>  
                                </cell>  
                                <cell class="loading"></cell>  
                            </list>  
                        </view>  
                    </swiper-item>  
                    <swiper-item class="swiper-item">  
                        <!-- 资料 -->  
                        <view class="uni-swiper-page">  
                            <list ref="list3" class="list" :offset-accuracy="5" :bounce="true" isSwiperList="true">  
                                <cell @click="onclick">  
                                    <view class="list-item" v-for="(item,index) in [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49]">  
                                        <text>资料{{item}}</text>  
                                    </view>  
                                </cell>  
                                <cell class="loading"></cell>  
                            </list>  
                        </view>  
                    </swiper-item>  
                </swiper>  
            </view>  
        </cell>  
    </list>  
</template>  

<script>  
    // #ifdef APP-PLUS  
    const dom = weex.requireModule('dom');  
    // #endif  
    // 缓存每页最多  
    const MAX_CACHE_DATA = 100;  
    // 缓存页签数量  
    const MAX_CACHE_PAGE = 3;  
    const TAB_PRELOAD_OFFSET = 1;  
    export default {  
        data() {  
            return {  
                tabIndex: 0,  
                cacheTab: [],  
                scrollInto: "",  
                indicatorLineLeft: 0,  
                indicatorLineWidth: 0,  
                isTap: false,  
                showTitleView: true,  
                statusHeight: 44,  
                pageHeight: 300,  
                refreshing: false,  
                refreshText: "",  
                refreshFlag: false  
            }  
        },  
        onLoad() {  

        },  
        onReady() {  
            let inf = uni.getSystemInfoSync();  
            this.statusHeight = inf.statusBarHeight; // 状态栏高度  
            this.pageHeight = inf.windowHeight - this.statusHeight - 200; // 页面高度  
            this._lastTabIndex = 0;  
            this.swiperWidth = 0;  
            this.tabbarWidth = 0;  
            this.tabListSize = {};  
            this._touchTabIndex = 0;  
            this._headHeight = 100;  
            this.selectorQuery();  

            // #ifdef APP-PLUS  
            plus.navigator.setStatusBarStyle("light"); //白色  
            // #endif  
        },  
        methods: {  

            setScrollRef(index, height) {  
                // Android不支持setSpecialEffects , 仅iOS机型生效  
                if (this.$refs['list' + index].setSpecialEffects) {  
                    this.$refs['list' + index].setSpecialEffects({  
                        id: "page",  
                        headerHeight: height //设置iOS端Tabs距离顶部的吸顶距离  
                    });  
                }  
            },  
            onclick(e) {  
                console.log("onclick");  
            },  
            loadData() {  
                // 首次激活时被调用  
            },  
            clear() {  
                // 释放数据时被调用,参考 swiper-list 缓存配置  
            },  

            ontap1(e) {  
                console.log("ontap1", e);  
            },  
            ontabtap(e) {  
                let index = e.target.dataset.current || e.currentTarget.dataset.current;  
                //let offsetIndex = this._touchTabIndex = Math.abs(index - this._lastTabIndex) > 1;  
                // #ifdef APP-PLUS || H5 || MP-WEIXIN || MP-QQ  
                this.isTap = true;  
                var currentSize = this.tabListSize[index];  
                this.updateIndicator(currentSize.left, currentSize.width);  
                this._touchTabIndex = index;  
                // #endif  
                this.switchTab(index);  
            },  
            onswiperchange(e) {  
                // 注意:百度小程序会触发2次  
                // #ifndef APP-PLUS || H5 || MP-WEIXIN || MP-QQ  
                let index = e.target.current || e.detail.current;  
                this.switchTab(index);  
                // #endif  
            },  
            onswiperscroll(e) {  
                if (this.isTap) {  
                    return;  
                }  
                var offsetX = e.detail.dx;  
                var preloadIndex = this._lastTabIndex;  
                if (offsetX > TAB_PRELOAD_OFFSET) {  
                    preloadIndex++;  
                } else if (offsetX < -TAB_PRELOAD_OFFSET) {  
                    preloadIndex--;  
                }  
                if (preloadIndex === this._lastTabIndex || preloadIndex < 0 || preloadIndex > 4 - 1) {  
                    return;  
                }  
                // if (this.pageList[preloadIndex].dataList.length === 0) {  
                //  this.loadTabData(preloadIndex);  
                // }  
                // #ifdef APP-PLUS || H5 || MP-WEIXIN || MP-QQ  
                var percentage = Math.abs(this.swiperWidth / offsetX);  
                var currentSize = this.tabListSize[this._lastTabIndex];  
                var preloadSize = this.tabListSize[preloadIndex];  
                var lineL = currentSize.left + (preloadSize.left - currentSize.left) / percentage;  
                var lineW = currentSize.width + (preloadSize.width - currentSize.width) / percentage;  
                this.updateIndicator(lineL, lineW);  
                // #endif  
            },  
            animationfinish(e) {  
                // #ifdef APP-PLUS || H5 || MP-WEIXIN || MP-QQ  
                let index = e.detail.current;  
                if (this._touchTabIndex === index) {  
                    this.isTap = false;  
                }  
                this._lastTabIndex = index;  
                this.switchTab(index);  
                this.updateIndicator(this.tabListSize[index].left, this.tabListSize[index].width);  
                // #endif  
            },  
            selectorQuery() {  
                // #ifdef APP-NVUE  
                //      uni.createSelectorQuery().in(this).select('#head').boundingClientRect().exec(rect => {  
                // // 获取封面区高度  
                // this._headHeight = rect[0].height;  
                //      });  
                uni.createSelectorQuery().in(this).select('#intro-box').boundingClientRect().exec(rect => {  
                    // 获取课程简介区的位置,设为iOS端Tabs距离顶部的吸顶距离  
                    this._headHeight = rect[0].height - 1;  
                    console.log('3 introHeight', this._headHeight);  
                });  
                // 查询 tabbar 宽度  
                uni.createSelectorQuery().in(this).select('#tab-bar').boundingClientRect().exec(rect => {  
                    this.tabbarWidth = rect[0].width;  
                });  
                // 查询 tabview 宽度  
                uni.createSelectorQuery().in(this).select('#tab-bar-view').boundingClientRect().exec(rect => {  
                    this.swiperWidth = rect[0].width;  
                });  
                // 因 nvue 暂不支持 class 查询  
                var queryTabSize = uni.createSelectorQuery().in(this);  
                queryTabSize.select('#tab0').boundingClientRect();  
                queryTabSize.select('#tab1').boundingClientRect();  
                queryTabSize.select('#tab2').boundingClientRect();  
                queryTabSize.select('#tab3').boundingClientRect();  
                queryTabSize.exec(rects => {  
                    rects.forEach((rect) => {  
                        this.tabListSize[rect.dataset.id] = rect;  
                    })  
                    this.updateIndicator(this.tabListSize[this.tabIndex].left, this.tabListSize[this.tabIndex]  
                        .width);  
                    this.switchTab(this.tabIndex);  
                });  
                // #endif  
                // #ifdef MP-WEIXIN || H5 || MP-QQ  
                uni.createSelectorQuery().in(this).select('.tab-view').fields({  
                    dataset: true,  
                    size: true,  
                }, (res) => {  
                    this.swiperWidth = res.width;  
                }).exec();  
                uni.createSelectorQuery().in(this).selectAll('.uni-tab-item').boundingClientRect((rects) => {  
                    rects.forEach((rect) => {  
                        this.tabListSize[rect.dataset.id] = rect;  
                    })  
                    this.updateIndicator(this.tabListSize[this.tabIndex].left, this.tabListSize[this.tabIndex]  
                        .width);  
                }).exec();  
                // #endif  
            },  
            updateIndicator(left, width) {  
                this.indicatorLineLeft = left;  
                this.indicatorLineWidth = width;  
            },  
            switchTab(index) {  
                // if (this.pageList[index].dataList.length === 0) {  
                //  this.loadTabData(index);  
                // }  
                this.setScrollRef(index,this._headHeight);  
                // if (this.tabIndex === index) {  
                //  return;  
                // }  
                // // 缓存 tabId  
                // if (this.pageList[this.tabIndex].dataList.length > MAX_CACHE_DATA) {  
                //  let isExist = this.cacheTab.indexOf(this.tabIndex);  
                //  if (isExist < 0) {  
                //      this.cacheTab.push(this.tabIndex);  
                //  }  
                // }  
                this.tabIndex = index;  
                // #ifdef APP-NVUE  
                this.scrollTabTo(index);  
                // #endif  
                // #ifndef APP-NVUE  
                this.scrollInto = "tab" + index;  
                // #endif  
                // 释放 tabId  
                // if (this.cacheTab.length > MAX_CACHE_PAGE) {  
                //  let cacheIndex = this.cacheTab[0];  
                //  this.clearTabData(cacheIndex);  
                //  this.cacheTab.splice(0, 1);  
                // }  
            },  
            scrollTabTo(index) {  
                const el = this.$refs['tabitem' + index][0];  
                let offset = 0;  
                // TODO fix ios offset  
                if (index > 0) {  
                    offset = this.tabbarWidth / 2 - this.tabListSize[index].width / 2;  
                    if (this.tabListSize[index].right < this.tabbarWidth / 2) {  
                        offset = this.tabListSize[0].width;  
                    }  
                }  
                dom.scrollToElement(el, {  
                    offset: -offset  
                });  
            },  
            loadTabData(index) {  
                // this.pageList[index].loadData();  
            },  
            clearTabData(index) {  
                // this.pageList[index].clear();  
            },  
            onrefresh(e) {  
                // this.refreshing = true;  
                // this.refreshText = "刷新中...";  
                // setTimeout(() => {  
                //  this.refreshing = false;  
                //  this.refreshFlag = false;  
                //  this.refreshText = "已刷新";  
                // }, 2000)  
            },  
            onpullingdown(e) {  
                if (this.refreshing) {  
                    return;  
                }  
                this.pulling = false;  
                if (Math.abs(e.pullingDistance) > Math.abs(e.viewHeight)) {  
                    this.refreshFlag = true;  
                    this.refreshText = "释放立即刷新";  
                } else {  
                    this.refreshFlag = false;  
                    this.refreshText = "下拉可以刷新";  
                }  
            }  
        }  
    }  
</script>  

<style>  
    /* #ifndef APP-PLUS */  
    page {  
        width: 100%;  
        min-height: 100%;  
        display: flex;  
    }  

    /* #endif */  
    .page {  
        flex: 1;  
    }  

    .cover-box {  
        width: 750rpx;  
        height: 200px;  
        flex-direction: row;  
        align-items: center;  
        justify-content: center;  
        background-color: #ffffff;  
    }  

    .status-bar {  
        height: 44px;  
        color: #ffffff;  
        background-color: #000000;  
    }  

    .intro-box {  
        height: 160px;  
        flex-direction: row;  
        align-items: center;  
        justify-content: center;  
        /* background-color: #f4f4f4; */  
    }  

    .flexible-view {  
        background-color: #f823ff;  
    }  

    .page-head {  
        height: 200px;  
        flex-direction: column;  
        align-items: center;  
        justify-content: center;  
        background-color: red;  
    }  

    .tabs {  
        flex-direction: column;  
        overflow: hidden;  
        background-color: #ffffff;  
        /* #ifdef MP-ALIPAY || MP-BAIDU */  
        height: 100vh;  
        /* #endif */  
    }  

    .tab-bar {  
        width: 750upx;  
        height: 84upx;  
        flex-direction: row;  
        /* #ifndef APP-PLUS */  
        white-space: nowrap;  
        /* #endif */  
    }  

    /* #ifndef APP-NVUE */  
    .tab-bar ::-webkit-scrollbar {  
        display: none;  
        width: 0 !important;  
        height: 0 !important;  
        -webkit-appearance: none;  
        background: transparent;  
    }  

    /* #endif */  
    .scroll-view-indicator {  
        position: relative;  
        height: 2px;  
        background-color: transparent;  
    }  

    .scroll-view-underline {  
        position: absolute;  
        top: 0;  
        bottom: 0;  
        width: 0;  
        background-color: #007AFF;  
    }  

    .scroll-view-animation {  
        transition-duration: 0.2s;  
        transition-property: left;  
    }  

    .tab-bar-line {  
        height: 1upx;  
        background-color: #cccccc;  
    }  

    .tab-view {  
        flex: 1;  
    }  

    .uni-tab-item {  
        /* #ifndef APP-PLUS */  
        display: inline-block;  
        /* #endif */  
        flex-wrap: nowrap;  
        padding-left: 25px;  
        padding-right: 25px;  
    }  

    .uni-tab-item-title {  
        color: #555;  
        font-size: 30upx;  
        height: 80upx;  
        line-height: 80upx;  
        flex-wrap: nowrap;  
        /* #ifndef APP-PLUS */  
        white-space: nowrap;  
        /* #endif */  
    }  

    .uni-tab-item-title-active {  
        color: #007AFF;  
    }  

    .swiper-item {  
        flex: 1;  
        flex-direction: column;  
    }  

    .swiper-page {  
        flex: 1;  
        flex-direction: row;  
        position: absolute;  
        left: 0;  
        top: 0;  
        right: 0;  
        bottom: 0;  
    }  

    .refresh-view {  
        width: 750rpx;  
        height: 80px;  
        flex-direction: row;  
        align-items: center;  
        justify-content: center;  
    }  
</style>  

<style scoped>  
    .uni-swiper-page {  
        flex: 1;  
        position: absolute;  
        left: 0;  
        top: 0;  
        right: 0;  
        bottom: 0;  
    }  
    .list {  
        flex: 1;  
        background-color: #ebebeb;  
    }  
    .list-item {  
        margin-left: 12px;  
        margin-right: 12px;  
        margin-top: 12px;  
        padding: 20px;  
        background-color: #fff;  
        border-radius: 5px;  
    }  
    .loading {  
        height: 20px;  
    }  
</style>

pages.json


{  
    "pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages  
        {  
            "path": "pages/index/index",  
            "style": {  
                "navigationBarTitleText": "uni-app",  
                "navigationStyle": "custom"  
            }  
        }  
    ],  
    "globalStyle": {  
        "navigationBarTextStyle": "black",  
        "navigationBarTitleText": "uni-app",  
        "navigationBarBackgroundColor": "#F8F8F8",  
        "backgroundColor": "#F8F8F8"  
    }  
}
收起阅读 »