jsonUrl.js 584 B

123456789101112131415161718192021222324252627282930
  1. function isObj(obj) {
  2. let array = Object.keys(obj);
  3. if (array.length === 0) { //如果数组array的长度为0 ,则返回为true,说明data对象为空
  4. return false;
  5. }
  6. return true;
  7. };
  8. // 配合to方法使用
  9. export const jsonUrl = (e) => {
  10. // #ifdef MP
  11. if (e.data) {
  12. e.data = decodeURIComponent(e.data)
  13. }
  14. // #endif
  15. if (isObj(e)) {
  16. if (e.data) {
  17. var data = JSON.parse(e.data)
  18. } else {
  19. return e;
  20. }
  21. return data;
  22. } else {
  23. uni.showToast({
  24. title: '参数错误',
  25. duration: 1000,
  26. icon: 'none',
  27. mask: true,
  28. });
  29. }
  30. }