Header.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <template>
  2. <div>
  3. <mu-appbar class="title" :title="title">
  4. <mu-icon-button slot="left">
  5. <img class="logo" src="https://www.vue-js.com/public/images/vue.png">
  6. </mu-icon-button>
  7. <mu-icon-menu slot="right" icon="more_vert" :value="theme" @change="changeTheme">
  8. <mu-menu-item title="LIGHT" value="light"/>
  9. <mu-menu-item title="CARBON" value="carbon"/>
  10. <mu-menu-item title="TEAL" value="teal"/>
  11. </mu-icon-menu>
  12. </mu-appbar>
  13. </div>
  14. </template>
  15. <script>
  16. import light from '!raw-loader!muse-ui/dist/theme-default.css'
  17. import carbon from '!raw-loader!muse-ui/dist/theme-carbon.css'
  18. import teal from '!raw-loader!muse-ui/dist/theme-teal.css'
  19. export default {
  20. data(){
  21. return {
  22. theme: 'light',
  23. themes: {
  24. light,
  25. carbon,
  26. teal
  27. }
  28. }
  29. },
  30. computed:{
  31. title: function () {
  32. return this.$store.state.titleMap.get(this.$route.path)
  33. }
  34. },
  35. methods: {
  36. changeTheme(theme) {
  37. this.theme = theme
  38. const styleEl = this.getThemeStyle()
  39. styleEl.innerHTML = this.themes[theme] || ''
  40. },
  41. getThemeStyle() {
  42. const themeId = 'muse-theme'
  43. let styleEl = document.getElementById(themeId)
  44. if (styleEl) return styleEl
  45. styleEl = document.createElement('style')
  46. styleEl.id = themeId
  47. document.body.appendChild(styleEl)
  48. return styleEl
  49. }
  50. }
  51. }
  52. </script>
  53. <style scoped>
  54. .title {
  55. text-align: center;
  56. height: 5rem;
  57. }
  58. .mu-icon-button {
  59. padding: 0.4rem;
  60. }
  61. </style>