fullscreen组件代码
<template> <el-button size="mini" :icon="value ? 'el-icon-monitor' : 'el-icon-full-screen'" @click="click">{{ value ? '恢复' : '全屏' }}</el-button> </template> <script> export default { props: ['value'],//变量名必须用value,否者不生效 methods: { click() { this.$emit('input', !this.value);//注意关键在input,变量名必须用value,否者不生效 }, } }; </script>
使用组件
... import fullscreen from "@/vue/components/fullscreen"; ... components: { fullscreen, }, ... <fullscreen v-model="isFullScreen"></fullscreen> ... isFullScreen:false,
进阶玩法:在同一个组件里面实现多个双向绑定↓