寫完調用天氣接口的demo之后,小程序調用天氣接口并且渲染在頁面,順便再調用了一下美圖的接口API:
美圖API
url
wxml:
<view class='imagesize' wx:for="{{list}}" wx:key="index"> <image src="{{list.img}}" class='in-image' > </image> </view>
js:
Page({ data: { list: [] }, onLoad: function (options) { wx.request({ url: 'https://api.apiopen.top/getImages', header: { 'content-type': 'application/json' }, success: res => { console.log(res.data) this.setData({ //第一個data為固定用法,第二個data是json中的data list: res.data.result[0], }) } }) }, })
css:
.imagesize { display: flex; justify-content: center; } .imagesize image { width: 400rpx; height: 400rpx; }
注意
以上代碼里面每次刷新的時候,都會隨機調用接口數據
因為接口文檔里面有說明,傳0或者不傳會隨機推薦圖片
所以我們在掉接口的時候可以在url后面綁定參數:
url: 'https://api.apiopen.top/getImages?page=1&count=2',
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com