vue接口异步请求
其他方法:
一:
getData: async function() { // 同步方法try { // 順序請求await this.getSetupList();await this.getRoleList();await this.getList();} catch (e) {} }二:
login: function(code) { // 定義方法return new Promise((resolve, reject) => {console.log(code)getThirdOpenid({ code: code }).then(response => { // 請求接口console.log(response)return response // 正確返回}).catch(res => {reject('獲取失敗') // 錯誤返回})}) }login(code).then(res => { // 調用同步方法// 返回正確的操作}).catch(res => {// 返回錯誤的操作 })三:
function login(code) {return new Promise((resolve, reject) => { // 同步方法getData1().then(response => { // 方法一return response // 返回正確值}).then((res) => {getData2().then((response) => { // 方法一返回正確后執行方法二return response // 返回正確值}).then((res) => {getData3().then(response => { // 方法二返回正確后執行方法三return response // 返回正確值}).then(res => {getData4().then(response => { // 方法三返回正確后執行方法四resolve(response ) // 方法執行完畢,拋出最后結果或進行某些操作}).catch(res => {reject('方法四返回錯誤')})}).catch(res => {reject('方法三返回錯誤')})}).catch(res => {reject('方法二返回錯誤')})}).catch(res => {reject('方法一返回錯誤')})}) }總結
- 上一篇: Request header field
- 下一篇: 小米商城app如何绑定银行卡(MIUI1