<button @click="togglePanel">点击</buttton> <div v-show="visible" ref="main">弹出层</div> export default { data () { return { visible: false } }, methods: { togglePanel () { this.visible ? this.hide() : this.show() }, show () { this.visible = true document.addEventListener('click', this.hidePanel, false) }, hide () { this.visible = false document.removeEventListener('click', this.hidePanel, false) }, hidePanel (e) { if (!this.$refs.main.contains(e.target)) { this.hide() } } }, beforeDestroy () { this.hide() } }