//app.js
App({
ajax:function(){
let that = this;
wx.request({
url: 'https://a.com/url.php',
method: 'GET',
success: function(e){
that.data = 123;
}
})
};
})
//content.js
let app = getApp()
Page({
getData: function(){;
app.ajax();
console.log(app.data); //undefined
}
})
//app.js
App({
ajax:function(){
let that = this;
let promise = new Promise(function(resolve, reject){
wx.request({
url: 'https://a.com/url.php',
method: 'GET',
success: function(e){
that.data = 123;
resolve();
}
})
});
};
})
//content.js
let app = getApp()
Page({
getData: function(){;
app.ajax().then(()=>{
console.log(app.data); //123
});
}
})
//search.js
var app = getApp();
Page({
confirm: function(e){
//获取数据,添加到全局
let val = e.detail.value;
app.searchWord = val;
this.jump();
},
jump: function(){
//跳转tabBar
wx.switchTab({
url: '../index/index',
});
},
});
//index.js
var app = getApp();
Page({
onShow: function(e){
//获取全局数据
let val = app.searchWord;
}
});
//需要传递参数的页面在跳转前将数据添加到app.js里。需要接受参数的页面在onShow方法接受之前添加到app.js的数据。
wx.request({
url: 'https://a.com/url.php',
data: {message: 123},
method: 'POST',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: function(e){
console.log(e)
}
});
wx.request({
url: url,
method: 'GET',
dataType: 'txt',
success: function(e){
let json = e.data.trim();
let arr = JSON.parse(json);
}
});
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有