微信小程序基础知识----内容页请求数据vvv

该代码段展示了在小程序中如何处理页面加载时的数据交互。首先,它检查本地存储中是否存在特定ID的缓存,然后使用Promise从服务器按条件获取数据,并设置导航栏标题。同时,代码还创建并配置了内部音频上下文以播放音乐。
摘要由CSDN通过智能技术生成

 

 

onLoad: function (options) {

    console.log(options)

     //判断当前页面是否有缓存

        let sto = wx.getStorageSync('storage');

        //判断对象中是否有指定的属性,返回布尔值

        let stoBool = sto.hasOwnProperty(options.id);//返回false

       //console.log(stoBool)

    //

    //promise的方法

    //从服务器获取数据,条件isgood>0

    //let that = this;

    let geturl=`${url}/db/cpntent.php?where=id=${options.id}`;

    

    util.getData2(geturl).then((res)=>{

       //console.log(res)//没用let

          res.pic=url+res.pic;

        

        this.setData({

          food:res

        })

          //动态设置导航栏标题

         wx.setNavigationBarTitle({

         title:res.title

         })

    })

   

    //绑定

    this.setData({

       //创建音频

      "IAC":wx.createInnerAudioContext(),

      "IAC.src":`${url}/images/music.mp3`,

      "IAC.loop":true 

    })

  },

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值