App.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <template>
  2. <div id="app">
  3. <RouterView />
  4. </div>
  5. </template>
  6. <script>
  7. import { getConfig } from '@/utils/auth';
  8. export default {
  9. name: 'App',
  10. created() {
  11. // 捕获未处理的错误
  12. window.onerror = (msg, url, lineNo, columnNo, error) => {
  13. console.log('onerror', msg, url, lineNo, columnNo, error);
  14. return true;
  15. };
  16. // 捕获未处理的 Promise 拒绝错误
  17. window.addEventListener('unhandledrejection', (event) => {
  18. // 阻止 Promise 拒绝默认行为
  19. event.preventDefault();
  20. // 获取拒绝的 Promise
  21. const promise = event.promise;
  22. promise.catch((e) => {
  23. console.log('catch', e);
  24. });
  25. // 获取拒绝的原因(错误)
  26. // const reason = event.reason;
  27. // 处理 Promise 拒绝错误
  28. // console.error('未捕获的 Promise.reject 错误:', reason);
  29. });
  30. this.setTitleIcon();
  31. },
  32. methods: {
  33. setTitleIcon() {
  34. const config = getConfig();
  35. if (config) {
  36. const link = document.querySelector("link[rel*='icon']") || document.createElement('link');
  37. link.type = 'image/x-icon';
  38. link.rel = 'shortcut icon';
  39. link.href = config.title_icon_url;
  40. document.getElementsByTagName('head')[0].appendChild(link);
  41. }
  42. }
  43. }
  44. };
  45. </script>