App.vue 969 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <template>
  2. <div id="app">
  3. <router-view v-if="routes.find((i) => i.path === $route.path)" />
  4. <layout v-else />
  5. <!-- <router-view /> -->
  6. </div>
  7. </template>
  8. <script>
  9. import { updateDocumentTitle } from '@/utils/document-title-util';
  10. import layout from '@/layout';
  11. import { routes } from './router/routes';
  12. export default {
  13. name: 'App',
  14. components: { layout },
  15. data () {
  16. return { routes };
  17. },
  18. created () {
  19. console.log(this.$route.path);
  20. // 恢复主题
  21. this.$store.dispatch('theme/recoverTheme');
  22. },
  23. methods: {
  24. /* 路由切换更新浏览器标题 */
  25. setDocumentTitle () {
  26. updateDocumentTitle(
  27. this.$route,
  28. (key) => this.$t(key),
  29. this.$store.state.theme.tabs
  30. );
  31. }
  32. },
  33. watch: {
  34. '$i18n.locale' () {
  35. this.setDocumentTitle();
  36. },
  37. $route () {
  38. this.setDocumentTitle();
  39. }
  40. }
  41. };
  42. </script>