关于小程序和后端的简单交互测试基本信息:
微信开发者工具版本:v1.02.2004020
记得勾选:

1.index.wxml
<view><button bindtap="getTest">获取数据</button></view>
<view wx:if="{{hello!=''}}">{{hello}}</view>
2.index.js在page中添加
getTest :function(){
var _this= this ;
wx.request({
url: 'http://localhost:8080/hello',
data: {},
header: {'content-type' : 'application/json'},
success: function(res){
console.log(res)
_this.setData({
hello:res.data
})
console.log(_this.data.hello)
}
3后端:怎么简单怎么来,只要请求返回一个json就行
@RequestMapping("/hello")
@ResponseBody
public String hello (){
return "hi world";
}
4.Console输出:


本文演示了一个微信小程序与SpringBoot后端进行简单交互的示例,包括使用微信开发者工具的版本、配置注意事项、后端接口设计以及如何查看Console输出来验证交互效果。
4万+

被折叠的 条评论
为什么被折叠?



