App.vue 3.27 KB
<template>
  <div id="app">
    <mu-drawer :open.sync="side_show" :docked="docked" :right="position === 'right'" :z-depth="1">
      <mu-list :value="default_list_index" @change="listChange">
        <mu-list-item :value="k" v-for="(v, k) in side_menu" :key="k" :to="v.url" @click="goTo()" button active-class="is-selected">
          <mu-list-item-title>{{ v.title }}</mu-list-item-title>
        </mu-list-item>
        <!-- <mu-list-item  @click="close" button>
          <mu-list-item-title>Close</mu-list-item-title>
        </mu-list-item> -->
      </mu-list>
    </mu-drawer>
    <mu-appbar :class="['mu-appbar-header', {'is-open': side_show}]" color="primary">
      <mu-button v-if="!side_show" @click="side_show = !side_show" icon slot="left">
        <mu-icon value="menu"></mu-icon>
      </mu-button>
      <p style="text-align: left;">Title</p>
      <mu-button flat slot="right">LOGIN</mu-button>
    </mu-appbar>
    <!-- <mu-row gutter>
      <mu-col span="4" sm="0" md="3" lg="2" xl="2">
        <side :show="show2"></side>
        123
      </mu-col>
      <mu-col span="8" sm="12" md="9" lg="10" xl="10">
        <mu-appbar style="width: 100%;" color="primary">
          <mu-button icon slot="left">
            <mu-icon value="menu"></mu-icon>
          </mu-button>
          Title

          <mu-button flat slot="right">LOGIN</mu-button>
        </mu-appbar>
        <p>111</p>
        <router-view/>
      </mu-col>
    </mu-row> -->
    <div :class="['main-contain', {'is-open': side_show}]">
      <router-view/>
    </div>
  </div>
</template>

<script>
// import side from 'components/side'

export default {
  components: {
    // side
  },
  mounted () {
    // 屏幕宽度小于600隐藏侧边栏
    this.resize($('body').width());
    // 键盘屏幕宽度
    $(window).resize(() => {
      // 屏幕宽度小于600隐藏侧边栏
      this.resize($('body').width());
    });
  },
  data () {
    return {
      default_list_index: 0,
      side_show: false,
      screen_width: '',
      docked: false,
      position: 'left',
      side_menu: [{
        title: 'Menu Item 1',
        url: '/'
      }, {
        title: 'Menu Item 2',
        url: '/test'
      }]
    }
  },
  methods: {
    resize (v) {
      // 屏幕宽度小于600隐藏侧边栏
      if (v <= 600) {
        this.side_show = false;
        this.docked = false;
      } else {
        this.side_show = true;
        this.docked = true;
      }
    },
    close () {
      // 关闭侧边栏
      this.side_show = false;
      $(window).resize()
    },
    goTo (v) {
      this.resize($('body').width());
    },
    listChange (v) {
      //
      this.default_list_index = v
    }
  }
}
</script>

<style lang="less">
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

.mu-appbar-header {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    z-index: 101;
    overflow: hidden
}

.mu-appbar-header.is-open {
    left: 256px;
}

.mu-appbar-header.is-only-title .mu-appbar-title {
    margin-left: 16px
}

.main-contain {
  top: 100px;
  position: relative;
}

.main-contain.is-open {
  left: 256px;
  width: calc(100% - 256px)
}

// .mu-item.is-selected {
//     color: #2196f3;
// }

</style>