美文网首页
11-动态设置页面标题

11-动态设置页面标题

作者: 早起的鸟儿 | 来源:发表于2019-11-06 16:06 被阅读0次

之前在每个页面的json文件里边设置的标题也都属于静态的,例如:

{
  "backgroundTextStyle": "light",
  "navigationBarBackgroundColor": "#42bd56",
  "navigationBarTitleText": "榜单",
  "navigationBarTextStyle": "white"
}

但是小程序给我们提供了动态修改标题的方法:

wx.setNavigationBarTitle({
   title: this.data.title
})

在需要修改标题的js中:

getHttp(res) {
    let That = this;
    That.setData({
      title: res.title, //影片名称
      large: res.images.large, //图片
      genres: res.genres, //影评类型
      countreies: res.countries, //影评来源
      year: res.year ,//上映时间
      rating: res.rating, //分数
      summary: res.summary, //简介
      casts: res.casts, //影人
      startItem:res
    })
    wx.setNavigationBarTitle({ 
     //必须写在setData的后面,否则只能获取到data中变量的初始值
      title: this.data.title;
    })
}

相关文章

网友评论

      本文标题:11-动态设置页面标题

      本文链接:https://www.haomeiwen.com/subject/rdnhmctx.html