getDeviceType.js 836 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. export default {
  2. mounted() {
  3. this.getDeviceType()
  4. },
  5. data() {
  6. return {
  7. // 设备类型pc,ios,android
  8. deviceType: 'pc'
  9. }
  10. },
  11. methods: {
  12. /**
  13. * 设备判断
  14. */
  15. getDeviceType() {
  16. if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) { //判断iPhone|iPad|iPod|iOS
  17. this.deviceType = 'ios';
  18. } else if (/(Android)/i.test(navigator.userAgent)) { //判断Android
  19. this.deviceType = 'android';
  20. } else { //pc
  21. };
  22. },
  23. /**
  24. * get cookie
  25. */
  26. getCookie() {
  27. const cookie = {};
  28. if (document && document.cookie) {
  29. document.cookie.split(/; ?/).forEach(item => {
  30. if (item) {
  31. const it = item.split('=');
  32. cookie[it[0]] = it[1];
  33. }
  34. });
  35. }
  36. return cookie;
  37. }
  38. }
  39. }