小程序
小游戏
企业微信
微信支付
扫描小程序码分享
之前测试的时候,用本地IP,开发工具可以获取到数据,真机测试的时候能请求到数据,但是现在真机却请求不到数据,接口都跑不过去是为什么
4 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
打开调试试一下 我之前在手机上就一直拿不到后台的数据 打开调试就好了
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
还是一样的,但是有时候用远程调试可以,有时候不可以,也是醉醉的
没有的,很简单的一个请求都不行
你好,请提供一下出现问题的机型和微信版本,以及能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。
note.js
var http = require("../../utils/util.js")
Page({
/**
* 页面的初始数据
*/
data: {
plusShow: true,
inputText: '',
ownSelf: false,
noteLists: [],//放置返回数据的数组
},
* 生命周期函数--监听页面加载
onLoad: function (options) {
onShow:function(){
this.getData(this.data.ownSelf, this.data.inputText)
// inputchange事件
bindChange: function (res) {
if (res.detail.value) {
this.setData({
plusShow: false
})
} else {
plusShow: true
}
inputText: res.detail.value
// 搜索事件
searchEvent: function () {
if (this.data.inputText) {
this.getData(false, this.data.inputText);
inputText: ''
wx.showModal({
content: '请输入搜索关键词',
showCancel: false
searchMeEvent: function () {
ownSelf: !this.data.ownSelf,
//搜索,访问网络
getData: function (isSelf, keyword) {
let that = this;
that.setData({
noteLists: []
var data = {
userId: getApp().globalData.userId,
isSelf: isSelf,
keyword: keyword
http.httpGet("get/note/note-lists", data, function (res) {
if (res.status == '10000') {
console.log(res)
noteLists: res.noteList
content: '笔记获取失败,可下拉重新获取',
showCancel: false,
onPullDownRefresh: function () {
this.getData(false, '')
wx.stopPullDownRefresh()
seeDetail: function (e) {
var that = this;
var fixData = {
coursename: e.currentTarget.dataset.coursename,
endtime: e.currentTarget.dataset.endtime,
grade: e.currentTarget.dataset.grade,
schoolname: e.currentTarget.dataset.schoolname,
subject: e.currentTarget.dataset.subject,
teacher: e.currentTarget.dataset.teacher
roomId: e.currentTarget.dataset.roomid
http.httpGet("get/note/note-details", data, function (res) {
if (res.status == '10002') {
wx.navigateTo({
url: '/pages/endClass/endClass?from=NoteList&roomId=' + e.currentTarget.dataset.roomid,
} else if (res.status == '10001') {
content: '该堂课无一人生成笔记,不可进入',
success: function (res) {
} else if (res.status == '10000') {
var authorName = res.authorName
var authorId = res.authorId
wx.setStorage({
key: "fixData",
data: fixData
url: '/pages/noteList/noteList?roomid=' + e.currentTarget.dataset.roomid + '&authorId=' + authorId + '&authorName=' + authorName + "&evaluated" + e.currentTarget.dataset.evaluated,
} else if (res.status == '-1') {
content: res.warn,
util.js
const formatTime = date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()
return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':')
const formatTime5 = date => {
return [year, month, day].map(formatNumber).join(',') + [hour, minute, second].map(formatNumber).join(',')
const formatTime1 = date => {
return [hour, minute].map(formatNumber).join(':')
const formatTime2 = date => {
return [hour, minute, second].map(formatNumber).join(':')
const formatTime3 = date => {
return [year, month, day].map(formatNumber).join('-')
const formatNumber = n => {
n = n.toString()
return n[1] ? n : '0' + n
// 接口
const config = {
LT_URl: 'http://192.168.1.5:2001/',
BASE_URL: 'http://192.168.1.7:2001/',
// get请求
function Get(url, data, cb) {
// wx.showNavigationBarLoading();//顶部显示loading效果
wx.showLoading({
title: '加载中',
mask: true
wx.request({
method: 'GET',
url: config.LT_URl + url,
data: data,
success: (res) => {
typeof cb == "function" && cb(res.data, "");
// wx.hideNavigationBarLoading();//顶部隐藏loading效果
wx.hideLoading()
fail: (err) => {
typeof cb == "function" && cb(null, err.errMsg);
console.log("get 请求:" + config.BASE_URL);
// console.log(err)
// wx.hideNavigationBarLoading();
};
// post请求
function Post(url, data, cb) {
method: 'POST',
header: {
"Content-Type": "application/json"//跨域请求
console.log("post 请求:" + config.BASE_URL);
// console.log(err);
content: err.errMsg,
});
function Gett(url, data, cb) {
url: config.BASE_URL + url,
// console.log("get 请求:" + config.BASE_URL);
function Postt(url, data, cb) {
"Content-Type": "application/x-www-form-urlencoded"//跨域请求
module.exports = {
formatTime: formatTime,
formatTime1: formatTime1,
formatTime2: formatTime2,
formatTime3: formatTime3,
config: config,
httpGet: Get,// 李婷
httpPost: Post,// 李婷
httpGett: Gett,
httpPostt: Postt
抱歉,请按照教程提供代码片段:https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html
wx:request未执行。上面是不是加判断条件了?
代码就像上面那么简单,开发工具编译可以看到数据,但是扫码真机就不行,一直再加载中,后台都收不到我的请求,好奇怪,之前做第一个项目的时候就可以
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
打开调试试一下 我之前在手机上就一直拿不到后台的数据 打开调试就好了
还是一样的,但是有时候用远程调试可以,有时候不可以,也是醉醉的
没有的,很简单的一个请求都不行
你好,请提供一下出现问题的机型和微信版本,以及能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。
note.js
var http = require("../../utils/util.js")
Page({
/**
* 页面的初始数据
*/
data: {
plusShow: true,
inputText: '',
ownSelf: false,
noteLists: [],//放置返回数据的数组
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
onShow:function(){
this.getData(this.data.ownSelf, this.data.inputText)
},
// inputchange事件
bindChange: function (res) {
if (res.detail.value) {
this.setData({
plusShow: false
})
} else {
this.setData({
plusShow: true
})
}
this.setData({
inputText: res.detail.value
})
},
// 搜索事件
searchEvent: function () {
if (this.data.inputText) {
this.getData(false, this.data.inputText);
this.setData({
inputText: ''
})
} else {
wx.showModal({
content: '请输入搜索关键词',
showCancel: false
})
}
},
searchMeEvent: function () {
this.setData({
ownSelf: !this.data.ownSelf,
})
this.getData(this.data.ownSelf, this.data.inputText)
this.setData({
inputText: ''
})
},
//搜索,访问网络
getData: function (isSelf, keyword) {
let that = this;
that.setData({
noteLists: []
})
var data = {
userId: getApp().globalData.userId,
isSelf: isSelf,
keyword: keyword
}
http.httpGet("get/note/note-lists", data, function (res) {
if (res.status == '10000') {
console.log(res)
that.setData({
noteLists: res.noteList
})
} else {
wx.showModal({
content: '笔记获取失败,可下拉重新获取',
showCancel: false,
})
}
})
},
onPullDownRefresh: function () {
this.getData(false, '')
wx.stopPullDownRefresh()
},
seeDetail: function (e) {
var that = this;
var fixData = {
coursename: e.currentTarget.dataset.coursename,
endtime: e.currentTarget.dataset.endtime,
grade: e.currentTarget.dataset.grade,
schoolname: e.currentTarget.dataset.schoolname,
subject: e.currentTarget.dataset.subject,
teacher: e.currentTarget.dataset.teacher
}
var data = {
userId: getApp().globalData.userId,
roomId: e.currentTarget.dataset.roomid
}
http.httpGet("get/note/note-details", data, function (res) {
if (res.status == '10002') {
wx.navigateTo({
url: '/pages/endClass/endClass?from=NoteList&roomId=' + e.currentTarget.dataset.roomid,
})
} else if (res.status == '10001') {
wx.showModal({
content: '该堂课无一人生成笔记,不可进入',
showCancel: false,
success: function (res) {
}
})
} else if (res.status == '10000') {
var authorName = res.authorName
var authorId = res.authorId
wx.setStorage({
key: "fixData",
data: fixData
})
wx.navigateTo({
url: '/pages/noteList/noteList?roomid=' + e.currentTarget.dataset.roomid + '&authorId=' + authorId + '&authorName=' + authorName + "&evaluated" + e.currentTarget.dataset.evaluated,
})
} else if (res.status == '-1') {
wx.showModal({
content: res.warn,
showCancel: false,
success: function (res) {
}
})
}
})
}
})
util.js
const formatTime = date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()
return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}
const formatTime5 = date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()
return [year, month, day].map(formatNumber).join(',') + [hour, minute, second].map(formatNumber).join(',')
}
const formatTime1 = date => {
const hour = date.getHours()
const minute = date.getMinutes()
return [hour, minute].map(formatNumber).join(':')
}
const formatTime2 = date => {
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()
return [hour, minute, second].map(formatNumber).join(':')
}
const formatTime3 = date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
return [year, month, day].map(formatNumber).join('-')
}
const formatNumber = n => {
n = n.toString()
return n[1] ? n : '0' + n
}
// 接口
const config = {
LT_URl: 'http://192.168.1.5:2001/',
BASE_URL: 'http://192.168.1.7:2001/',
}
// get请求
function Get(url, data, cb) {
// wx.showNavigationBarLoading();//顶部显示loading效果
wx.showLoading({
title: '加载中',
mask: true
})
wx.request({
method: 'GET',
url: config.LT_URl + url,
data: data,
success: (res) => {
typeof cb == "function" && cb(res.data, "");
// wx.hideNavigationBarLoading();//顶部隐藏loading效果
wx.hideLoading()
},
fail: (err) => {
typeof cb == "function" && cb(null, err.errMsg);
console.log("get 请求:" + config.BASE_URL);
// console.log(err)
// wx.hideNavigationBarLoading();
wx.hideLoading()
}
})
};
// post请求
function Post(url, data, cb) {
wx.showLoading({
title: '加载中',
mask: true
})
wx.request({
method: 'POST',
url: config.LT_URl + url,
data: data,
header: {
"Content-Type": "application/json"//跨域请求
},
success: (res) => {
typeof cb == "function" && cb(res.data, "");
wx.hideLoading()
},
fail: (err) => {
typeof cb == "function" && cb(null, err.errMsg);
console.log("post 请求:" + config.BASE_URL);
// console.log(err);
wx.showModal({
content: err.errMsg,
showCancel: false,
})
wx.hideLoading()
}
});
};
// get请求
function Gett(url, data, cb) {
// wx.showNavigationBarLoading();//顶部显示loading效果
wx.showLoading({
title: '加载中',
mask: true
})
wx.request({
method: 'GET',
url: config.BASE_URL + url,
data: data,
success: (res) => {
typeof cb == "function" && cb(res.data, "");
// wx.hideNavigationBarLoading();//顶部隐藏loading效果
wx.hideLoading()
},
fail: (err) => {
typeof cb == "function" && cb(null, err.errMsg);
// console.log("get 请求:" + config.BASE_URL);
// console.log(err)
// wx.hideNavigationBarLoading();
wx.hideLoading()
}
})
};
// post请求
function Postt(url, data, cb) {
wx.showLoading({
title: '加载中',
mask: true
})
wx.request({
method: 'POST',
url: config.BASE_URL + url,
data: data,
header: {
"Content-Type": "application/x-www-form-urlencoded"//跨域请求
},
success: (res) => {
typeof cb == "function" && cb(res.data, "");
wx.hideLoading()
},
fail: (err) => {
typeof cb == "function" && cb(null, err.errMsg);
console.log("post 请求:" + config.BASE_URL);
// console.log(err);
wx.showModal({
content: err.errMsg,
showCancel: false,
})
wx.hideLoading()
}
});
};
module.exports = {
formatTime: formatTime,
formatTime1: formatTime1,
formatTime2: formatTime2,
formatTime3: formatTime3,
config: config,
httpGet: Get,// 李婷
httpPost: Post,// 李婷
httpGett: Gett,
httpPostt: Postt
}
抱歉,请按照教程提供代码片段:https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html
wx:request未执行。上面是不是加判断条件了?
代码就像上面那么简单,开发工具编译可以看到数据,但是扫码真机就不行,一直再加载中,后台都收不到我的请求,好奇怪,之前做第一个项目的时候就可以