Merge pull request #2668 from lison16/layout

update Layout
This commit is contained in:
Aresn 2017-12-21 10:00:38 +08:00 committed by GitHub
commit baa75b0aef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 11 deletions

View file

@ -4,6 +4,7 @@
<Sider <Sider
v-model="isCollapsed" v-model="isCollapsed"
collapsed-width="0" collapsed-width="0"
hide-trigger
collapsible collapsible
ref="side" ref="side"
width="200"> width="200">
@ -29,6 +30,7 @@
</MenuItem> </MenuItem>
</MenuGroup> </MenuGroup>
</Menu> </Menu>
<!-- <div slot="trigger"><Icon type="document-text"></Icon></div> -->
</Sider> </Sider>
<Layout class-name="test-class"> <Layout class-name="test-class">
<Header :style="{background: '#eee'}"><Button @click="toggleCollapse">菜单</Button></Header> <Header :style="{background: '#eee'}"><Button @click="toggleCollapse">菜单</Button></Header>
@ -51,6 +53,11 @@ export default {
toggleCollapse () { toggleCollapse () {
this.$refs.side.toggleCollapse(); this.$refs.side.toggleCollapse();
} }
},
watch: {
isCollapsed (val) {
// console.log(val)
}
} }
}; };
</script> </script>

View file

@ -8,9 +8,11 @@
<div :class="childClasses"> <div :class="childClasses">
<slot></slot> <slot></slot>
</div> </div>
<slot name="trigger">
<div v-show="showBottomTrigger" :class="triggerClasses" @click="toggleCollapse" :style="{width: siderWidth + 'px'}"> <div v-show="showBottomTrigger" :class="triggerClasses" @click="toggleCollapse" :style="{width: siderWidth + 'px'}">
<i :class="triggerIconClasses"></i> <i :class="triggerIconClasses"></i>
</div> </div>
</slot>
</div> </div>
</template> </template>
<script> <script>
@ -39,7 +41,6 @@
}, },
breakpoint: { breakpoint: {
type: String, type: String,
default: 'md',
validator (val) { validator (val) {
return oneOf(val, ['xs', 'sm', 'md', 'lg', 'xl']); return oneOf(val, ['xs', 'sm', 'md', 'lg', 'xl']);
} }
@ -115,8 +116,8 @@
methods: { methods: {
toggleCollapse () { toggleCollapse () {
this.isCollapsed = this.collapsible ? !this.isCollapsed : false; this.isCollapsed = this.collapsible ? !this.isCollapsed : false;
this.$emit('input', !this.isCollapsed); this.$emit('input', this.isCollapsed);
this.$emit('on-collapse', !this.isCollapsed); this.$emit('on-collapse', this.isCollapsed);
}, },
matchMedia () { matchMedia () {
let matchMedia; let matchMedia;
@ -137,15 +138,23 @@
} }
}, },
mounted () { mounted () {
on(window, 'resize', this.onWindowResize);
this.matchMedia();
this.$emit('input', this.defaultCollapsed);
if (this.defaultCollapsed) { if (this.defaultCollapsed) {
this.isCollapsed = true; this.isCollapsed = true;
this.$emit('input', this.defaultCollapsed);
} else {
if (this.value !== undefined) {
this.isCollapsed = this.value;
}
}
if (this.breakpoint !== undefined) {
on(window, 'resize', this.onWindowResize);
this.matchMedia();
} }
}, },
destroyed () { beforeDestroy () {
if (this.breakpoint !== undefined) {
off(window, 'resize', this.onWindowResize); off(window, 'resize', this.onWindowResize);
} }
}
}; };
</script> </script>