后端:公告√
注意数据库新建notice表
This commit is contained in:
26
frontend/common/http.js
Normal file
26
frontend/common/http.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import { API_BASE_URL, SHOP_ID } from './config.js'
|
||||
|
||||
function buildUrl(path) {
|
||||
if (!path) return API_BASE_URL
|
||||
if (path.startsWith('http')) return path
|
||||
return API_BASE_URL + (path.startsWith('/') ? path : '/' + path)
|
||||
}
|
||||
|
||||
export function get(path, params = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
url: buildUrl(path),
|
||||
method: 'GET',
|
||||
data: params,
|
||||
header: { 'X-Shop-Id': SHOP_ID },
|
||||
success: (res) => {
|
||||
const { statusCode, data } = res
|
||||
if (statusCode >= 200 && statusCode < 300) return resolve(data)
|
||||
reject(new Error('HTTP ' + statusCode))
|
||||
},
|
||||
fail: (err) => reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user