debugger.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import Vue from 'vue'
  2. let log = function (title, object) {
  3. let currentUrl = ""
  4. // #ifdef H5
  5. currentUrl = window.location.href
  6. // #endif
  7. console.log("┏━━━━━ 打印开始 Url: " + currentUrl + " ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
  8. if (!object) {
  9. object = title
  10. } else {
  11. //创建新数组,存放数据及样式
  12. let arr1 = [''];
  13. //给每一个黑字设置样式
  14. arr1[0] += '%c' + title;
  15. //用随机函数生成三位数代表rgb颜色
  16. let random1 = randomFunc();
  17. arr1[1] = 'color:#fff;font-size:15px;background-color:#' + random1;
  18. console.log.apply(console, arr1)
  19. }
  20. let jsonStr = JSON.stringify(object, null, 2);
  21. //创建新数组,存放数据及样式
  22. let arr = [''];
  23. //给每一个黑字设置样式
  24. arr[0] += '%c' + jsonStr;
  25. //用随机函数生成三位数代表rgb颜色
  26. let random = randomFunc();
  27. arr[1] = 'color:#fff;font-size:15px;background-color:#' + random;
  28. //arr[1]='font-size:15px;color:#'+random;
  29. console.log.apply(console, arr)
  30. console.log("┗━━━━━ 打印结束 Url: " + currentUrl + " ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
  31. }
  32. let randomFunc = function () {
  33. let random = Math.random().toFixed(3) * 1000;
  34. if (random <= 100) {
  35. return randomFunc();
  36. } else {
  37. return random;
  38. }
  39. }
  40. // 添加到 Vue原型链
  41. // 临时调试方法
  42. Vue.prototype.$log = log
  43. // #ifdef H5
  44. window.log = log
  45. // #endif