小程式雲api封裝

2021-09-25 13:51:52 字數 1279 閱讀 2088

const tip = (text) => )

}//查詢

export const dbget = (param)=>)

} const promise = new promise((resolve, reject) =>

}).catch(err => )

}else

}).catch(err => )}})

return promise

}//新增或者更新資料

export const dbadd = (param) => )

} const promise = new promise((resolve, reject) => ;

if (param.where))

}else)

}control.then(res => )

.catch(err=>)

})return promise

}//刪除資料或檔案

export const dbdel = (param) => )

if (param.fileid))}}

}})

})return promise

}//上傳

export const dbupload = (param) => )

//檔名稱

let filepath = res.tempfilepaths[0];

const name = parseint(math.random() * 1000000000);

const cloudpath = namestr + name + filepath.match(/\.[^.]+?$/)[0]

if (param.fileid))

}//上傳檔案到伺服器

wx.cloud.uploadfile().then(res=>

});}).then(res=>);}})

})return promise

}

import  from '../../utils/api';

//查詢

dbget().then((data)=>)

})//條件查詢

dbget().then((datas) => )

})//上傳

dbupload().then(res => )

//替換上傳

dbupload().then(res => )

//新增 帶where就是替換 否則是新新增

dbadd().then(res => )

小程式封裝api請求

測試環境 test 生產環境 prod const api require api.js const config require env index.js const fetch require fetch.js let env prod let baseurl config env baseur...

微信小程式開發API封裝

專案url相通部分,減輕 量,同時方便專案遷移 get請求,不需要傳參,直接url呼叫 function getdata url,dosuccess ethod get success function res 這裡時匯出 module.exports.getdata getdata page裡面隨...

微信小程式封裝API介面

2.新建資料夾http,api是封裝的介面函式,env是設定公共訪問的url,http是二次封裝wx.request 3.env.js 設定公共訪問的url,即環境變數 module.exports 測試環境 test 線上環境 引入env中的url const require env.js pro...