main.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import { createSSRApp } from 'vue'
  2. import App from './App.vue'
  3. // #ifdef H5
  4. import VConsole from 'vconsole'
  5. // #endif
  6. // Polyfill for String.prototype.startsWith (for older browsers)
  7. if (!String.prototype.startsWith) {
  8. String.prototype.startsWith = function(search, pos) {
  9. pos = !pos || pos < 0 ? 0 : +pos
  10. return this.substring(pos, pos + search.length) === search
  11. }
  12. }
  13. // Polyfill for String.prototype.endsWith (for older browsers)
  14. if (!String.prototype.endsWith) {
  15. String.prototype.endsWith = function(search, this_len) {
  16. if (this_len === undefined || this_len > this.length) {
  17. this_len = this.length
  18. }
  19. return this.substring(this_len - search.length, this_len) === search
  20. }
  21. }
  22. // Polyfill for String.prototype.includes (for older browsers)
  23. if (!String.prototype.includes) {
  24. String.prototype.includes = function(search, start) {
  25. if (typeof start !== 'number') {
  26. start = 0
  27. }
  28. if (start + search.length > this.length) {
  29. return false
  30. } else {
  31. return this.indexOf(search, start) !== -1
  32. }
  33. }
  34. }
  35. // Polyfill for Array.prototype.includes (for older browsers)
  36. if (!Array.prototype.includes) {
  37. Array.prototype.includes = function(searchElement, fromIndex) {
  38. if (this == null) {
  39. throw new TypeError('"this" is null or not defined')
  40. }
  41. var o = Object(this)
  42. var len = o.length >>> 0
  43. if (len === 0) {
  44. return false
  45. }
  46. var n = fromIndex | 0
  47. var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0)
  48. while (k < len) {
  49. if (o[k] === searchElement) {
  50. return true
  51. }
  52. k++
  53. }
  54. return false
  55. }
  56. }
  57. // Polyfill for String.prototype.repeat (for older browsers)
  58. if (!String.prototype.repeat) {
  59. String.prototype.repeat = function(count) {
  60. if (this == null) {
  61. throw new TypeError("can't convert " + this + ' to object')
  62. }
  63. var str = '' + this
  64. count = +count
  65. if (count != count) {
  66. count = 0
  67. }
  68. if (count < 0) {
  69. throw new RangeError('repeat count must be non-negative')
  70. }
  71. if (count == Infinity) {
  72. throw new RangeError('repeat count must be less than infinity')
  73. }
  74. count = Math.floor(count)
  75. if (str.length == 0 || count == 0) {
  76. return ''
  77. }
  78. if (str.length * count >= 1 << 28) {
  79. throw new RangeError('repeat count must not overflow maximum string size')
  80. }
  81. var maxCount = str.length * count
  82. count = Math.floor(Math.log(count) / Math.log(2))
  83. while (count) {
  84. str += str
  85. count--
  86. }
  87. str += str.substring(0, maxCount - str.length)
  88. return str
  89. }
  90. }
  91. // Polyfill for String.prototype.padStart (for older browsers)
  92. if (!String.prototype.padStart) {
  93. String.prototype.padStart = function padStart(targetLength, padString) {
  94. targetLength = targetLength >> 0
  95. padString = String(typeof padString !== 'undefined' ? padString : ' ')
  96. if (this.length >= targetLength) {
  97. return String(this)
  98. } else {
  99. targetLength = targetLength - this.length
  100. if (targetLength > padString.length) {
  101. padString += padString.repeat(targetLength / padString.length)
  102. }
  103. return padString.slice(0, targetLength) + String(this)
  104. }
  105. }
  106. }
  107. // Polyfill for String.prototype.padEnd (for older browsers)
  108. if (!String.prototype.padEnd) {
  109. String.prototype.padEnd = function padEnd(targetLength, padString) {
  110. targetLength = targetLength >> 0
  111. padString = String(typeof padString !== 'undefined' ? padString : ' ')
  112. if (this.length >= targetLength) {
  113. return String(this)
  114. } else {
  115. targetLength = targetLength - this.length
  116. if (targetLength > padString.length) {
  117. padString += padString.repeat(targetLength / padString.length)
  118. }
  119. return String(this) + padString.slice(0, targetLength)
  120. }
  121. }
  122. }
  123. // 初始化vConsole用于移动端调试
  124. // #ifdef H5
  125. new VConsole()
  126. // #endif
  127. export function createApp() {
  128. const app = createSSRApp(App)
  129. return {
  130. app
  131. }
  132. }