vue中找到el-dropdown-menu的隐藏
时间: 2023-12-30 21:04:46 浏览: 98
可以使用Vue指令`v-show`或者`v-if`来控制`el-dropdown-menu`的显示与隐藏。
使用`v-show`指令,示例代码如下:
```
<el-dropdown>
<span class="el-dropdown-link">
下拉菜单<i class="el-icon-arrow-down el-icon--right"></i>
</span>
<el-dropdown-menu v-show="showDropdown">
<el-dropdown-item>菜单项一</el-dropdown-item>
<el-dropdown-item>菜单项二</el-dropdown-item>
<el-dropdown-item>菜单项三</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
```
在Vue组件中定义`showDropdown`变量,来控制`el-dropdown-menu`的显示与隐藏:
```
<template>
<el-dropdown>
<span class="el-dropdown-link" @click="showDropdown = !showDropdown">
下拉菜单<i class="el-icon-arrow-down el-icon--right"></i>
</span>
<el-dropdown-menu v-show="showDropdown">
<el-dropdown-item>菜单项一</el-dropdown-item>
<el-dropdown-item>菜单项二</el-dropdown-item>
<el-dropdown-item>菜单项三</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</template>
<script>
export default {
data() {
return {
showDropdown: false
};
}
};
</script>
```
使用`v-if`指令的示例代码如下:
```
<el-dropdown>
<span class="el-dropdown-link">
下拉菜单<i class="el-icon-arrow-down el-icon--right"></i>
</span>
<el-dropdown-menu v-if="showDropdown">
<el-dropdown-item>菜单项一</el-dropdown-item>
<el-dropdown-item>菜单项二</el-dropdown-item>
<el-dropdown-item>菜单项三</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
```
在Vue组件中定义`showDropdown`变量,来控制`el-dropdown-menu`的显示与隐藏:
```
<template>
<el-dropdown>
<span class="el-dropdown-link" @click="showDropdown = !showDropdown">
下拉菜单<i class="el-icon-arrow-down el-icon--right"></i>
</span>
<el-dropdown-menu v-if="showDropdown">
<el-dropdown-item>菜单项一</el-dropdown-item>
<el-dropdown-item>菜单项二</el-dropdown-item>
<el-dropdown-item>菜单项三</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</template>
<script>
export default {
data() {
return {
showDropdown: false
};
}
};
</script>
```
以上是两种常用的控制`el-dropdown-menu`显示与隐藏的方法,具体使用哪种方法,可以根据实际需求来选择。
阅读全文