// pages/meishi/meishi.js
Page({
/**
word: result.detail.value
})/**
},
//text
requestNetwork: function(){
wx.request({
url: https://apis.tianapi.com/dream/index?key= 5ca3892a9ad11ad15cdcb2bb69d5af8f
, //仅为示例,并非真实的接口地址
method:'GET',
data: {
num:5,
dreamResult:this.data.word
},
success: function (res){
console.log(res)
//请求成功回调
//获取栈中的页面数量
var pages = getCurrentPages();
//获取到当前页面
var index = pages[pages.length - 1];
index.setData({
//设置结果码
})
self.setData({
dreamResult:res.data.result.list,
dreamCode:res.data.result.code
})}
})
},
/**
},
/**
},
/**
},
/**
},
/**
},
/**
}
})
<!--pages/meishi/meishi.wxml-->
<input bindinput="inputWord" auto-focus placeholder="请输入" type="text"/>
<button type='primary' bindtap='requestNetwork'>请求数据</button>
<view wx:for="{{dreamResult}}" wx:for-index="id" wx:for-item="item" wx:key="id">
<view>{{id}}梦到{{item.title}}--------{{item.result}}</view>
</view>
应该是this出问题了,wx.request里边this的指向应该不是page了,试试设置下let that = this ,然后在请求里用that.data.word