Header.vue 1.8 KB

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