elementplus?card?懸浮菜單的實現(xiàn)
業(yè)務(wù)上需要實現(xiàn)一個功能,以卡片形式顯示機器列表,當懸浮到卡片上時,在卡片上方向上滑出操作菜單。經(jīng)過一番嘗試總算實現(xiàn)了。效果如下:

<script setup lang="ts">
import { useRouter } from 'vue-router'
import { ElCard, ElRow, ElCol, ElProgress, ElIcon, ElButton } from 'element-plus'
import { ref } from 'vue'
const router = useRouter()
const visible = ref(false)
const monitor = (e: any) => {
router.push('/dashboard/workplace')
e.stopPropagation()
}
const control = (e: any) => {
window.open('http://localhost:6080/vnc.html')
e.stopPropagation()
}
</script>
<template>
<el-row>
<el-card
class="box-card"
shadow="hover"
@click="monitor"
@mouseleave="visible = !visible"
@mouseenter="visible = !visible"
>
<el-row justify="center"><Icon icon="svg-icon:windows" :size="40" /></el-row>
<el-row class="row" justify="center">主機1</el-row>
<el-row class="row" align="middle">
<el-col :span="6" class="text">CPU</el-col>
<el-col :span="18">
<el-progress :percentage="50" />
</el-col>
</el-row>
<el-row class="row" align="middle">
<el-col :span="6" class="text">內(nèi)存</el-col>
<el-col :span="18">
<el-progress :percentage="50" />
</el-col>
</el-row>
<el-row class="row" align="middle">
<el-col :span="6" class="text">硬盤</el-col>
<el-col :span="18">
<el-progress :percentage="50" />
</el-col>
</el-row>
<transition name="slide">
<div class="card-pop-menu" v-show="visible">
<el-row>
<el-col :span="12">
<ElButton type="primary" plain @click="monitor">監(jiān)控</ElButton>
</el-col>
<el-col :span="12">
<ElButton type="primary" plain>編輯</ElButton>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<ElButton type="primary" plain @click="control">控制臺</ElButton>
</el-col>
<el-col :span="12">
<ElButton type="danger" plain>刪除</ElButton>
</el-col>
</el-row>
</div>
</transition>
</el-card>
<el-card class="box-card" shadow="hover">
<el-row justify="center" align="middle" style="height: 200px">
<el-icon color="#409EFC" size="40">
<Plus />
</el-icon>
</el-row>
</el-card>
</el-row>
</template>
<style lang="less" scoped>
.box-card {
width: 240px;
height: 240px;
margin: 0 20px 20px 0;
.row {
margin-top: 14px;
}
.text {
font-size: 14px;
}
.card-pop-menu {
border-width: 1px 0 0 0;
position: relative;
top: -34px;
width: 238px;
height: 88px;
margin: -20px;
button {
width: 100%;
height: 44px;
border-width: 0;
border-radius: 0;
}
}
}
.slide-enter-active {
transition: all 0.2s linear;
}
.slide-leave-active {
transition: all 0.2s linear;
}
.slide-enter-from,
.slide-leave-to {
transform: translateY(88px);
}
</style>補:使用el-card第一行沒有對齊解決方法
當使用element plus的el-card組件時候,第一行和后面會沒有對齊。
<el-row>
<el-col v-for="(o, index) in 10" :key="o" :span="6" :offset="index >= 0 ? 2 : 0">
<el-card :body-style="{ padding: '0px' }">
<img
src="https://shadow.elemecdn.com/app/element/hamburger.9cf7b091-55e9-11e9-a976-7f4d0b07eef6.png"
class="image"
/>
<div style="padding: 14px">
<span>Yummy hamburger</span>
<div class="bottom">
<time class="time">{{ currentDate }}</time>
<el-button text class="button">Operating</el-button>
</div>
</div>
</el-card>
</el-col>
</el-row>
原因是el-col添加了offset列偏移。第一項沒有偏移。將其改成:
<el-col v-for="(o, index) in 10" :key="o" :span="6" :offset="index >= 0 ? 1 : 0">

到此這篇關(guān)于elementplus card 懸浮菜單的實現(xiàn)的文章就介紹到這了,更多相關(guān)elementplus card 懸浮菜單內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- element-ui 設(shè)置菜單欄展開的方法
- Element-Ui組件 NavMenu 導(dǎo)航菜單的具體使用
- Element Dropdown下拉菜單的使用方法
- vue3使用element-plus搭建后臺管理系統(tǒng)之菜單管理功能
- 解決elementui中NavMenu導(dǎo)航菜單高亮問題(解決多種情況)
- Vue3+Element-Plus實現(xiàn)左側(cè)菜單折疊與展開功能示例
- Vue使用element-ui實現(xiàn)菜單導(dǎo)航
- vue.js+element-ui動態(tài)配置菜單的實例
- vue+element使用動態(tài)加載路由方式實現(xiàn)三級菜單頁面顯示的操作
- Vue+element-ui添加自定義右鍵菜單的方法示例
相關(guān)文章
vue項目拍照或上傳圖片并實現(xiàn)轉(zhuǎn)化為base64格式
這篇文章主要介紹了vue項目拍照或上傳圖片并實現(xiàn)轉(zhuǎn)化為base64格式方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-11-11
基于vue2.0+vuex+localStorage開發(fā)的本地記事本示例
這篇文章主要介紹了基于vue2.0+vuex+localStorage開發(fā)的本地記事本示例,具有一定的參考價值,感興趣的小伙伴們可以參考一下。2017-02-02

