elementplus?card?懸浮菜單的實(shí)現(xiàn)
業(yè)務(wù)上需要實(shí)現(xiàn)一個(gè)功能,以卡片形式顯示機(jī)器列表,當(dāng)懸浮到卡片上時(shí),在卡片上方向上滑出操作菜單。經(jīng)過(guò)一番嘗試總算實(shí)現(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">主機(jī)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">控制臺(tái)</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>補(bǔ):使用el-card第一行沒(méi)有對(duì)齊解決方法
當(dāng)使用element plus的el-card組件時(shí)候,第一行和后面會(huì)沒(méi)有對(duì)齊。
<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列偏移。第一項(xiàng)沒(méi)有偏移。將其改成:
<el-col v-for="(o, index) in 10" :key="o" :span="6" :offset="index >= 0 ? 1 : 0">

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

