http.js
const $http = (url='',data={},mothod='GET',header={})=>{
const baseUrl = 'https://www.baidu.com'
let promise = new Promise((resolve,reject)=>{
uni.request({
url:baseUrl+url,
data,
method,
header
}).then(res=>{
if(res.status==200){
resolve(res.data)
}else{
reject(res.message)
}
}).catch(err=>{
reject(err)
})
})
return promise
}
export default $http
api.js
import $http from ./http.js'
const gethome = ()=>$http('/api/list?toke=111')
export {
gethome
}
home.vue
<script>
import {gethome} from '../http/api.js'
export default {
data() {
orderList:[]
},
onLoad() {
this.list()
},
methods: {
list(){
gethome().then(res=>{
console.log(res)
}).catch(err=>{
console.log(err)
})
}
}
}
</script>