sendReqMixin.js 774 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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) {
  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':
  26. params.contentType || 'application/json;charset=utf-8',
  27. },
  28. }).then(
  29. (res) => {
  30. if (res && res.data) {
  31. callback && callback(res.data)
  32. }
  33. },
  34. (error) => {
  35. throw new Error(error)
  36. }
  37. )
  38. },
  39. },
  40. }