uni-app的tabBar用法(自动、点击刷新页面,loading加载框)

一.先在package.json中配置tabBar(前置条件)

tabBar所跳转的页面应事先在page中创建好!如下配置后app下方会有可点击的tabBar按钮,在list中设置按钮的个数。

 图1

        tabBar的list属性

        text:tabBar按钮的名称

        pagePath:tabBar按钮的page页面路径

        iconPath:未选中时的按钮图片

        selectedIconPath:选中时的按钮图片

        visible:默认开启和关闭某个tabBar按钮

        iconfont:tabBar底部的字体显示

 图2

二.tabBar的点击事件

1.tabBar的刷新事件

(1)点击tabBar自动刷新页面   onTabItemTap(e)

<template>
  <div>
    <web-view :src="url" ref="webView"></web-view>
  </div>
</template>

<script>
export default {
  data() {
    return {
      url: 'https://www.baidu.com', // 外部网页的URL
    };
  },
  methods: {

    //点击tabBar自动刷新页面
    onTabItemTap(e) {
      this.url = '';
      // 异步重新设置 src,相当于刷新 web-view
      setTimeout(() => {
        this.url = 'https://www.baidu.com';
      }, 100);
    },
  },
};
</script>

2.给点击页面的时候增加一个loading加载框

<template>
  <div>
    <web-view :src="url" ref="webView"></web-view>
  </div>
</template>

<script>
export default {
  data() {
    return {
      url: 'https://www.baidu.com', // 外部网页的URL
    };
  },
  methods: {

    //点击tabBar自动刷新页面
    onTabItemTap(e) {
      this.url = '';
      // 异步重新设置 src,相当于刷新 web-view
      setTimeout(() => {
        this.url = 'https://www.baidu.com';
      }, 100);
    },
  },
  mounted() {
    this.refreshWebView();
  },

  //给点击tabBar时加一个1s的loading加载框
  watch: {
    url(newUrl) {
      if (newUrl === '') {
        uni.showToast({
          title: '加载中',
          icon: 'loading',
          duration: 1000,
        });
      }
    },
  },
  created() {
    uni.hideToast();
  },
  beforeDestroy() {
    uni.hideToast();
  },
  destroyed() {
    uni.hideToast();
  },
};
</script>

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值