setTabBarBadge在非tabBar页面设置

2024-01-20 00:48

本文主要是介绍setTabBarBadge在非tabBar页面设置,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

不支持,需要在tabBar栏操作。

可以换种思路,在本页面遮罩层实现业务逻辑,这样没有离开tabBar页面,就可以操作setTabBarBadge。

wxml 添加到主页面最下面即可

<!-- 遮罩层 -->
<!-- <view class="shadow" wx:if="{{chooseSize}}" bindtap='hideModal'></view> -->
<!-- 上滑高度 -->
<view class='choosen' wx:if="{{chooseSize}}" animation='{{animationData}}'><!-- 内容 --><view class="container-box"><view class="close"><image src="/images/close.png" bindtap="hideModal"></image></view><view class="picture"><image src="{{detail.imageUrl}}"></image></view><view class="detail_leg"><view class="dish">{{detail.name}}</view><view class="Sold">已售{{detail.number}}份</view><view class="price"><text>¥{{detail.real}}</text><text style="font-size: 20rpx;text-decoration: line-through;color:#000;">¥{{detail.price}}</text><image src="/images/add.png" data-id="{{detail.id}}" bindtap="detailAddCarts"></image></view></view></view>
</view>

wxss 

/*弹窗*/
/* .shadow{width: 100%;height: 200%;z-index: 80;position: absolute;top: 0;background-color: #000;opacity: 0.5;
} */
/* 上滑高度 */
.choosen{width: 100%;height: 100%;position: fixed;bottom: 0;background-color: #fff;/* border-top-left-radius: 20rpx;border-top-right-radius: 20rpx; */z-index: 98;
}/* 内容 */
.container-box {display: flex;height: 100%;flex-direction: column;width: 100%;border-radius: 15rpx;margin: 0 auto;z-index: 98;
}.close{position: fixed;right: 30rpx;top: 30rpx;
}
.close image{height: 60rpx;width: 60rpx;
}.picture{height: 60%;width: 100%;}
.picture image{height: 100%;width: 100%;
}.dish{font-size: 48rpx;font-weight: bold;
}
.Sold{margin-top: 10rpx;font-size: 20rpx;
}
.price{margin-top: 10rpx;color: red;
}
.price image{height: 50rpx;width: 50rpx;position: fixed;right: 40rpx;
}

js

 detailAddCarts: function (event) {let productId = this.data.productIdconsole.log(this.data);let product = this.data.products.find(element => element.id == productId); //根据id获取商品数据// let product = this.data.products.find(detail); //根据id获取商品数据console.log(product)//检测购物车中是否已经存在某个商品if (this.data.carts.includes(product)) {this.data.carts.find(element => element.id == productId).count++; //不添加商品,直接数量加1} else {this.data.carts.push(product); //添加商品}app.globalData.carts = this.data.carts;console.log(app.globalData.carts);wx.setTabBarBadge({index: 2,text: app.globalData.carts.length.toString()})},//商品详情页是上滑showshadow: function(e) {let productId_detail = e.currentTarget.dataset.id; //获取商品idlet product_detail = this.data.products.find(element => element.id == productId_detail); //根据id获取商品数据console.log(product_detail)var _that = this;_that.setData({detail: product_detail,productId: productId_detail,})if (this.data.chooseSize == false) {this.chooseSezi()} else {this.hideModal()}},// 动画函数chooseSezi: function(e) {// 用that取代this,防止不必要的情况发生var that = this;// 创建一个动画实例var animation = wx.createAnimation({// 动画持续时间duration: 400,// 定义动画效果,当前是匀速timingFunction: 'linear'})// 将该变量赋值给当前动画that.animation = animation// 先在y轴偏移,然后用step()完成一个动画animation.translateY(1000).step()// 用setData改变当前动画that.setData({// 通过export()方法导出数据animationData: animation.export(),// 改变view里面的Wx:ifchooseSize: true})// 设置setTimeout来改变y轴偏移量,实现有感觉的滑动 滑动时间setTimeout(function() {animation.translateY(0).step()that.setData({animationData: animation.export(),clearcart: false})}, 100)},// 隐藏hideModal: function(e) {var that = this;var animation = wx.createAnimation({duration: 400,timingFunction: 'linear'})that.animation = animationanimation.translateY(700).step()that.setData({animationData: animation.export()})setTimeout(function() {animation.translateY(0).step()that.setData({animationData: animation.export(),chooseSize: false})}, 500)}

 

 

这篇关于setTabBarBadge在非tabBar页面设置的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/624269

相关文章

微信小程序uniappvue3版本-控制tabbar某一个的显示与隐藏

1. 首先在pages.json中配置tabbar信息 2. 在代码根目录下添加 tabBar 代码文件 直接把微信小程序文档里面的四个文件复制到自己项目中就可以了   3. 根据自己的需求更改index.js文件 首先我这里需要判断什么时候隐藏某一个元素,需要引入接口 然后在切换tabbar时,改变tabbar当前点击的元素 import getList from '../

flutter TabBar+PageView联动

import 'dart:io'; import 'package:flutter/services.dart'; import 'package:flutter/material.dart'; void main() {   runApp(new MyApp());   if (Platform.isAndroid) {     // 以下两行 设置android状态栏为透明的沉浸。写在组件渲

小程序获取自定义tabbar高度踩坑

在小程序中使用自定义tabbar后,页面page高度会包含自定义tabbar高度,为了方便页面布局,可以获取tabbar高度后,用calc(100% - {{tabbarHeight}})来计算。 坑点:发现用tdesign自定义tabbar组件后,小程序无法正确获取高度,经测试可以做如下修改: 1.custom-tab-bar/index.wxml,在tdesign组件外层添加view,并

IOS 17 基于UITabBarController实现首页TabBar

实现方式 创建首页MainController继承自UITabBarController就可以实现Tabbar效果。 实现效果 创建几个子控制器 创建子控制器 DiscoveryController,VideoController,MeController,FeedController,RoomController,继承自BaseLogicController;BaseLogicCon

uni-app - - - - - 自定义tabbar

uni-app - - - - - 自定义tabbar 1. 创建页面2. pages.json3. 自定义tabbar4. 隐藏原生tabbar5. 全局注册组件6. 页面使用7. 效果图展示 1. 创建页面 2. pages.json 配置tabbar {"tabBar": {"list": [{"pagePath": "pages/ballroom/ballroom

自定义tabbar跳转防止页面抖动(uniapp案例,也适用所有前端项目)

自定义tabbar思路就是自己写个tabbar组件引入到tabbar页面内,使每个页面显示也会有这个组件显示,但是这样的话,每次点击由于tabbar是作为页面组件使用的,会跟着组件的渲染和销毁一起执行,导致每次页面显示就会有抖动效果,解决方式为:做一个主页面,将tabbar页面引入进去,同时把该tabbar对应的页面也引入进去,这样的话只需要一个页面执行显示和隐藏就行了,也不会导致tabbar组

web前端之选项卡集合、动态添加类名、动态移除类名、动态添加样式、激活、间距、节流、tabBar

MENU input的checked属性(Html+Style)伪元素(Html+Style+JavaScript)激活类(Html+Style+JavaScript)vue伪元素 input的checked属性(Html+Style) 前言 代码段创建一个使用HTML和CSS实现的标签式内容切换组件。通过选择不同的标签,可以展示相应的内容。 代码段实现一个简洁的标签切换

【TabBar嵌套Navigation案例-推送和提醒界面的内容 Objective-C语言】

一、使用兑换码这个页面,看一下示例程序 1.当我点击这个使用兑换码Cell的时候,我要跳到另一个页面, 我要跳到一个控制器,这是一个普通的控制器,然后呢,这个页面啊,怎么着来做,首先,我要点击这个Cell,做一些事情,那我肯定要有它的点击事件, 这是第一,然后呢,接下来啊,我先来写,一会儿我们再来去说,我们先来用普通的正常的方式,大家都熟悉的方式,先来写,首先,在这个里边,我们说

微信小程序开发---自定义底部tabBar

自定义tabBar注意事项: 在自定义 tabBar 模式下 ,为了保证低版本兼容以及区分哪些页面是 tab 页,app.json文件中 tabBar 的相关配置项需完整声明,但这些字段不会作用于自定义 tabBar 的渲染。所有 tabBar 的样式都由该自定义组件渲染。推荐用 fixed 在底部的 cover-view + cover-image 组件渲染样式,以保证 tabBar 层级相对

vant报错:Unknown custom element: <van-tabbar>

Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the “name” option. found in —> at src/views/layout/index.vue at src/App.vue 在使用v