data: {
voteTitle:null,
simple:false,
}
voteTitle: function (e) {
this.setData({ simple:true,voteTitle:e.detail.value})
var that = this
wx.request({
url: 'https://api.shanbay.com/bdc/search/?word=' + this.data.voteTitle.toLowerCase(),
data: {},
method: 'GET',
success: function (res) {
that.setData({
word: res.data.data.content,
pron: res.data.data.pronunciation,
definition: res.data.data.definition,
pron_audio: res.data.data.audio
})
}
})
this.setData({
simple: true
})
},
read(){
const innerAudioContext = wx.createInnerAudioContext()
innerAudioContext.autoplay = true
innerAudioContext.src = this.data.pron_audio
},
})
<view class="page">
<view class="input_counter">
<input class="input" placeholder="输入要查询的单词" bindinput="voteTitle"> </input>
</view>
<view wx:if="{{simple}}" class="simple_look">
<view style="font-size:45rpx;" bindtap="read"> {{word}} 【{{pron}}】</view>
<view style="height:10px;"></view>
<view>{{definition}}</view>
</view>
</view>
url: 'https://api.shanbay.com和其他需要请求的域名
没添加到后台安全域名里面去吧。
编译的 预览的