Blogger Information
Blog 67
fans 0
comment 2
visits 71784
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
uniapp请求封装
搁浅
Original
833 people have browsed it

http.js

  1. const $http = (url='',data={},mothod='GET',header={})=>{
  2. const baseUrl = 'https://www.baidu.com'
  3. let promise = new Promise((resolve,reject)=>{
  4. uni.request({
  5. url:baseUrl+url,
  6. data,
  7. method,
  8. header
  9. }).then(res=>{
  10. if(res.status==200){
  11. resolve(res.data)
  12. }else{
  13. reject(res.message)
  14. }
  15. }).catch(err=>{
  16. reject(err)
  17. })
  18. })
  19. return promise
  20. }
  21. export default $http

api.js

  1. import $http from ./http.js'
  2. const gethome = ()=>$http('/api/list?toke=111')
  3. export {
  4. gethome
  5. }

home.vue

  1. <script>
  2. import {gethome} from '../http/api.js'
  3. export default {
  4. data() {
  5. orderList:[]
  6. },
  7. onLoad() {
  8. this.list()
  9. },
  10. methods: {
  11. list(){
  12. gethome().then(res=>{
  13. console.log(res)
  14. }).catch(err=>{
  15. console.log(err)
  16. })
  17. }
  18. }
  19. </script>
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post