el-drawer 抽屉怎么关闭
时间: 2024-06-13 10:07:17 浏览: 10
要关闭el-drawer抽屉,可以使用子组件中的方法来触发父组件中的事件,从而改变抽屉的状态。具体实现步骤如下:
1.在父组件中,使用v-on指令监听子组件触发的事件,并在事件处理函数中修改抽屉的状态,例如:
```html
<template>
<div>
<el-button @click="drawer = true">打开抽屉</el-button>
<el-drawer :visible.sync="drawer" direction="ltr" :show-close="false" size="30%" :lock-scroll="false" z-index="20000">
<child-component @closeD="handleClose"></child-component>
</el-drawer>
</div>
</template>
<script>
import ChildComponent from './ChildComponent.vue'
export default {
components: {
ChildComponent
},
data() {
return {
drawer: false
}
},
methods: {
handleClose(val) {
this.drawer = val
}
}
}
</script>
```
2.在子组件中,使用$emit方法触发事件,并传递参数,例如:
```html
<template>
<div>
<el-button @click="closeDrawer">关闭抽屉</el-button>
</div>
</template>
<script>
export default {
methods: {
closeDrawer() {
this.$emit('closeD', false)
}
}
}
</script>
```
这样,当子组件中的按钮被点击时,就会触发父组件中的handleClose方法,从而关闭抽屉。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)