index.wxml
通过一个输入框把url的id传给js
<input type="text" placeholder="输入id" name="search" value="" placeholder-class="plac" bindinput="inputValue" />
<view >
<text>城市:{{data.City}}</text>
<view></view>
<text>公司名:{{data.CustomerID}}</text>
</view>
index.js
event.detail.value接收传来的id,字符串拼接成url,并发送wx.request请求
url java后台访问数据库代码见
https://blog.youkuaiyun.com/qw160/article/details/115700896?spm=1001.2014.3001.5501
// index.js
// 获取应用实例
const app = getApp()
Page({
data: {
inputValue: "",
},
/**输入函数 */
inputValue: function (event) {
this.setData({
inputValue: event.detail.value
})
console.log(this.data)
console.log(event.detail.value)
let that=this;
wx.request({
url: 'http://localhost:8080/json/'+event.detail.value,
data:{},
method:'GET',
header:{
'content-type' : 'application'
},
success: function(res){
that.setData({
data:res.data,
});
}
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
}
})