123456789101112131415161718192021222324252627282930313233343536 |
- import {mapState} from 'vuex'
- export default {
- computed: {
- ...mapState('m_user', ['userinfo'])
- },
- watch: {
- // 监听 count 值的变化
- 'userinfo.count': {
- handler() {
- // 调用 methods 中的 setBadge 方法,重新为 tabBar 的数字徽章赋值
- this.setBadge()
- }
- },
- },
- onShow() {
- // 在页面刚展示的时候,设置数字徽标
- this.setBadge()
- },
- methods: {
- setBadge() {
- if (this.userinfo.count == 0) {
- uni.removeTabBarBadge({
- index: 2
- })
- } else {
- // 调用 uni.setTabBarBadge() 方法,为购物车设置右上角的徽标
- uni.setTabBarBadge({
- index: 2,
- text: this.userinfo.count + '', // 注意:text 的值必须是字符串,不能是数字
- })
- }
-
- }
- }
- }
|