page.json
{
"path" : "pages/content/detail-article/detail-article",
"style" :
{
"navigationBarTitleText": "",
"enablePullDownRefresh": false,
"app-plus": {
"titleNView": {
"buttons": [{
"type": "share"
},
{
"text": "\ue505",
"fontSrc": "/static/iconfont.ttf",
"fontSize": "22px"
}
]
}
}
}
}
页面里:
onNavigationBarButtonTap(event) {
const buttonIndex = event.index;
if (buttonIndex === 1) {
console.log('收藏');
//这里要调用接口,设置this.isStar的值,下面代码是设置图标用的
// #ifdef APP-PLUS
var currentWebview = this.$mp.page.$getAppWebview();
var tn = currentWebview.getStyle().titleNView;
var text = tn.buttons[1].text;
console.log(this.isStar);
if(this.isStar){
tn.buttons[1].text = '\ue505';
this.isStar = false;
}else{
tn.buttons[1].text = '\ue630';
this.isStar = true;
}
currentWebview.setStyle({
titleNView: tn
});
// #endif
}
}
这是一个关于小程序页面中导航栏按钮点击事件的处理。当用户点击收藏按钮时,会根据`isStar`的值改变按钮的文字,并通过接口更新状态。在APP-PLUS环境下,通过获取当前Webview的样式,修改导航栏的按钮文字,实现了按钮状态的切换效果。
1295

被折叠的 条评论
为什么被折叠?



