12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <template>
- <div id="app">
- <RouterView />
- <GlobalProgress />
- </div>
- </template>
- <script>
- import { getConfig } from '@/utils/auth';
- import GlobalProgress from '@/components/GlobalProgress.vue';
- export default {
- name: 'App',
- components: {
- GlobalProgress,
- },
- created() {
- // 捕获未处理的错误
- window.onerror = (msg, url, lineNo, columnNo, error) => {
- console.error('onerror', msg, url, lineNo, columnNo, error);
- return true;
- };
- // 捕获未处理的 Promise 拒绝错误
- window.addEventListener('unhandledrejection', (event) => {
- // 阻止 Promise 拒绝默认行为
- event.preventDefault();
- // 获取拒绝的 Promise
- const promise = event.promise;
- promise.catch((e) => {
- console.error('catch', e);
- });
- // 获取拒绝的原因(错误)
- // const reason = event.reason;
- // 处理 Promise 拒绝错误
- // console.error('未捕获的 Promise.reject 错误:', reason);
- });
- this.setTitleIcon();
- },
- methods: {
- setTitleIcon() {
- const config = getConfig();
- if (config) {
- const link = document.querySelector("link[rel*='icon']") || document.createElement('link');
- link.type = 'image/x-icon';
- link.rel = 'shortcut icon';
- link.href = config.title_icon_url;
- document.getElementsByTagName('head')[0].appendChild(link);
- }
- },
- },
- };
- </script>
|