微信小程序动态设置标题名称

5 阅读1分钟

微信小程序开发技巧:动态设置标题名称 当某个界面作为公共界面,需要更加功能名称动态设置标题名称。 下面为具体实现代码


    
    onLoad(options) {
        //查询产品信息
        this.loadProductInfo(options.id);
  },
  
  // 加载商品信息
  async loadProductInfo(id) {
    //根据ID查询产品信息
    const productInfoRes = await reqProductById(id);
    if (productInfoRes) {
      this.setData({
        productInfo: productInfoRes.data
      })
    }

    //修改标题
**    //设置标题名称
    wx.setNavigationBarTitle({
      title: this.data.productInfo.productName
    });**
  },