天行数据土味情话API接口调用
注册天行数据账号申请"土味情话"接口下载微信开发工具创建一个空项目将下面的key填到是链接上即可请求成功/topnews/index?key=KEY
// pages/index/index.jsPage({/*** 页面的初始数据*/data: {// 渲染到视图层//返回内容更新到视图层{{tianapi_data}}tianapi_data: []},/*** 生命周期函数--监听页面加载*/onLoad: function () {//微信小程序参考代码,请确保在小程序后台设置了安全域名wx.request({url: '/saylove/index',method: 'POST',data: {key: '53791645XXXe1ac656e85482f2bf7XXX'},header: {'Content-Type': 'application/x-www-form-urlencoded'},success: res => {if (res.data.code == 200) {//1:在控制台打印一下返回的res.data数据console.log(res.data)//2:在请求接口成功之后,用setData接收数据this.setData({//第一个data为固定用法tianapi_data: res.data})}},fail: function (err) {console.log(err)}})}})
index.html
<!--pages/index/index.wxml--><view class="container"><view class="crad"><view wx:for="{{tianapi_data}}" class="content">{{item.content}}</view></view><navigator url="/pages/index/index" hover-class="none"><view class="title">换一句~</view></navigator></view>
index.wxss
/* pages/index/index.wxss */.crad{/* 内部边距 */padding: 10px;/* 宽度 */width: 90%;height: 100px;border-radius: 10px;box-shadow: 0 0 5px 5px #e9e9e9;background-color: #f0f0f0;}.content{color: #798586;/* 斜体 */font-style: oblique;}.title{color: rgb(255, 255, 255);text-align: center;padding: 10px;width: 100px;margin: 15px;border-radius: 50px;box-shadow: 0 0 5px 5px #e9e9e9;background-color: rgb(132, 159, 233);}