1、微信小程序,没有vue那么复杂
app.js
globalData: {
userInfo: null,
height: 0,
API_URL: ‘自己的网络接口’ https://,
// 用户是否已经登录
isLogin: false,
},
2、在页面中js引入
eg:
// 获取应用实例
const app = getApp()
var API_URL = app.globalData.API_URL;
在请求中应用
// 获取地址信息
getAddress () {
var that = this
wx.request({
url: API_URL + '接口',
method: "POST",
data: {
userid : wx.getStorageSync('userid'),
},
header: { 'content-type': 'application/x-www-form-urlencoded' },
success: function (res) {// success
} else {
}
}
})
},