|
2 | 2 | <view> |
3 | 3 | <page-head :title="title"></page-head> |
4 | 4 | <view class="uni-padding-wrap uni-common-mt"> |
5 | | - <view class="uni-title"> |
6 | | - <uni-icon size="16" type="info"></uni-icon>说明 : </view> |
| 5 | + <view class="uni-title"> <uni-icon size="16" type="info"></uni-icon>说明 : </view> |
7 | 6 | <view class="uni-helllo-text"> |
8 | | - <view>在App端可在pages.json里配置buttons,暂不支持动态改变buttons的样式,使用onNavigationBarButtonTap可监听buttons的点击事件。</view> |
| 7 | + <view |
| 8 | + >在App端可在pages.json里配置buttons,暂不支持动态改变buttons的样式,使用onNavigationBarButtonTap可监听buttons的点击事件。</view |
| 9 | + > |
9 | 10 | <view>在小程序和h5端,不支持配置buttons,故按钮不见了。</view> |
10 | 11 | </view> |
11 | 12 | </view> |
12 | 13 | </view> |
13 | 14 | </template> |
14 | 15 | <script> |
15 | | - import uniIcon from '../../../components/uni-icon.vue' |
16 | | - export default { |
17 | | - data() { |
18 | | - return { |
19 | | - title: 'nav-button' |
| 16 | +import uniIcon from '../../../components/uni-icon.vue'; |
| 17 | +export default { |
| 18 | + data() { |
| 19 | + return { |
| 20 | + title: 'nav-dot' |
| 21 | + }; |
| 22 | + }, |
| 23 | + onLoad() { |
| 24 | + this.setStyle(0,true); |
| 25 | + this.setStyle(1,'20'); |
| 26 | +
|
| 27 | + }, |
| 28 | + methods: { |
| 29 | + /** |
| 30 | + * 修改导航栏buttons |
| 31 | + * index[number] 修改的buttons 下标索引,最右边索引为0 |
| 32 | + * text[boolean|string] 需要修改的text 内容 ,如果定义redDot请设置 true||false ,如果定义badgeText请设置具体数字,如果没有输入'' |
| 33 | + */ |
| 34 | + setStyle(index, text) { |
| 35 | + let pages = getCurrentPages(); |
| 36 | + let page = pages[pages.length - 1]; |
| 37 | + // #ifdef APP-PLUS |
| 38 | + let currentWebview = page.$getAppWebview(); |
| 39 | + let titleNView = currentWebview.getStyle().titleNView; |
| 40 | +
|
| 41 | + let dot = titleNView.buttons[index].redDot; |
| 42 | + let badgeText = titleNView.buttons[index].badgeText; |
| 43 | + if (dot) { |
| 44 | + titleNView.buttons[index].redDot = text; |
20 | 45 | } |
21 | | - }, |
22 | | - onNavigationBarButtonTap(e) { |
23 | | - uni.showToast({ |
24 | | - title: e.index === 0 ? "你点了分享按钮" : "你点了收藏按钮", |
25 | | - icon: "none" |
26 | | - }) |
27 | | - if(e.index === 0){ |
28 | | - |
29 | | - }else{ |
30 | | - |
| 46 | + if (badgeText) { |
| 47 | + titleNView.buttons[index].badgeText = text; |
31 | 48 | } |
32 | | - }, |
33 | | - components:{ |
34 | | - uniIcon |
| 49 | + currentWebview.setStyle({ |
| 50 | + titleNView: titleNView |
| 51 | + }); |
| 52 | + // #endif |
35 | 53 | } |
| 54 | + }, |
| 55 | + onNavigationBarButtonTap(e) { |
| 56 | + uni.showToast({ |
| 57 | + title: e.index === 0 ? '你点了消息按钮' : '你点了关注按钮', |
| 58 | + icon: 'none' |
| 59 | + }); |
| 60 | + // 取消红点或者角标 |
| 61 | + this.setStyle(e.index, e.index === 0 ? false : ''); |
| 62 | + }, |
| 63 | + components: { |
| 64 | + uniIcon |
36 | 65 | } |
| 66 | +}; |
37 | 67 | </script> |
38 | 68 |
|
39 | | -<style> |
40 | | - |
41 | | -</style> |
| 69 | +<style></style> |
0 commit comments