sendReqMixin.js 786 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * 发送请求 mixin
  3. */
  4. import request from './server'
  5. /* eslint-disable */
  6. export const sendReq = {
  7. data () {
  8. return {
  9. // 加载中
  10. loading: false,
  11. }
  12. },
  13. methods: {
  14. /*
  15. * 发送请求
  16. */
  17. sendReq (params, callback, errorCallback) {
  18. let self = this
  19. request({
  20. method: params.method || 'POST',
  21. url: params.url,
  22. data: params.data || {},
  23. withCredentials : true,
  24. headers: {
  25. 'Content-type': params.contentType || 'application/json;charset=utf-8'
  26. }
  27. }).then((res) => {
  28. if (res && res.data) {
  29. callback && callback(res.data)
  30. }
  31. }).catch(err => {
  32. if (err) {
  33. errorCallback && errorCallback(err)
  34. }
  35. })
  36. }
  37. }
  38. }