控制器正常查询数据表,建议不要使用分页这些,会有默认封装的各种格式,处理起来可能偏繁琐,注意返回:
直接 return json($data);
不要去搞神马php转换为json之类的,数据会出错,我就是犯了这个低级错误。
<template><view class="page-body"><!-- raw_active start --><view v-for="(item, index) in activeArr" :key="index" class="raw_active"><image :src="item.ac_img"></image><view class="active-box"><img src="../../static/images/Home.png" alt='Home.png' :style="{width: '30rpx',height: '28rpx',marginRight: '10rpx'}"><text class="font-34 tit">{
{item.ac_name}}</text><span class="btns" @click="turnInfo(item.ac_id)">详情</span></view> </view><!-- raw_active end --> </view>
</template><script>export default {data() {return {activeArr: '',index: 0}},onLoad () {uni.request({url: 'http://192.168.8.192:802/public/index.php/index/commonmodule/activewgy', //接口地址 header: {'content-type':'application/json'},method: 'POST',success: (res) => {this.activeArr = res.data //拿到数据直接使用就是//console.log(res.data) } })},methods: { turnInfo (id) {uni.navigateTo({//url: ''})}} }
</script><style scoped>
</style>
补充一下微信小程序的获取方式
<view class="raw" wx:for="{
{reglist1}}" wx:key="key"><view class="raw_list"><view class="img_box"><image src="https://xxxxxxxxxxx.com/public/upload/user/{
{item.d_img}}"></image></view><view class="txt_box"><h3>{
{item.d_name}}</h3> <view class="icon">预约</view><text>{
{item.d_goodat}}</text></view></view>
Page({/*** 页面的初始数据*/data: {reglist1: [], //院外专家reglist2: [] //院内专家},/*** 生命周期函数--监听页面加载*/onLoad: function (options) {var that = this;//发起网络请求wx.request({ url: 'https://xxxxxxxx.com/public/index.php/index/users/index',method: 'POST', dataType: 'json',success: function (res){//console.log(res.data);that.setData({reglist1: res.data.info1,reglist2: res.data.info2}); //console.log(reglist1);},fail: function (res) {console.log(res.data);}})}
})
跨域问题,在BaseController.php
// 初始化
protected function initialize()
{//访问XMLHttpRequest已被CORS政策阻止//header("Access-Control-Allow-Origin: *");// 指定允许其他域名访问 header('Access-Control-Allow-Origin:*');// 响应类型 header('Access-Control-Allow-Methods:*');// 响应头设置 header('Access-Control-Allow-Headers:*');//header('Access-Control-Allow-Headers:x-requested-with,content-type'); //允许ajax异步请求带cookie信息header('Access-Control-Allow-Credentials:true');
}