index.js 494 B

12345678910111213141516171819202122
  1. import { ref } from 'vue'
  2. import { onLoad } from '@dcloudio/uni-app'
  3. export default (separator = '?') => {
  4. let urlQuery = ref('')
  5. onLoad(options => {
  6. const scene = decodeURIComponent(options.q)
  7. const arr = scene.split(separator)
  8. const length = arr.length
  9. urlQuery = arr[length - 1]
  10. })
  11. return {
  12. getQueryString (name) {
  13. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i")
  14. var r = urlQuery.match(reg)
  15. if (r != null) return unescape(r[2])
  16. return null
  17. }
  18. }
  19. }