亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

vue實現(xiàn)右鍵彈出菜單

 更新時間:2022年07月15日 09:25:15   作者:早起的小笨雞  
這篇文章主要為大家詳細介紹了vue實現(xiàn)右鍵彈出菜單,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

在最近工作中,有一個需求,需要做一個表格,并且對該表格右鍵彈出菜單支持增刪改,這里做下總結(jié),功能截圖如下:

首先定義菜單結(jié)構(gòu)

<!-- 菜單 -->
<div class="menu-list" :style="{position:'fixed',top:top+'px',left:left+'px'}" v-if="visible">
? ? <div class="menu" v-for="(item,index) in menuList">
? ? ? ?  <div v-if="item=='插入圖片'||item=='更換圖片'">
? ? ? ? ? ?? <el-upload class="upload-demo"
? ? ? ? ? ? ? ? ? ? ? ? ?action=""
? ? ? ? ? ? ? ? ? ? ?   ?:accept="$pubTool.UPLOADIMGFORMAT"
? ? ? ? ? ? ? ? ? ? ? ? ?:auto-upload="false"
? ? ? ? ? ? ? ? ? ? ? ?  :show-file-list="false"
? ? ? ? ? ? ? ? ? ? ? ? ?:limit="1"
? ? ? ? ? ? ? ? ? ? ? ? ?:on-exceed="(files) => { selectedFileMore(files, 'img', 'script_filePath', 0,0, 1, 'NONE', false); addImg(); }"
? ? ? ? ? ? ? ? ? ? ? ? ?:on-change="(file) => { selectedFile(file, 'img', 'script_filePath', 0,0, 1, 'NONE', false); addImg(); }">
? ? ? ? ? ? ? ? ? ? ? ? <div>{{item}}</div>
? ? ? ? ? ? ? ? ? ? </el-upload>
? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? ? <div v-if="item=='插入視頻'||item=='更換視頻'">
? ? ? ? ? ? ? ? ? ? <el-upload class="upload-demo"
? ? ? ? ? ? ? ? ? ? ? ? ?action=""
? ? ? ? ? ? ? ? ? ? ? ? ?:accept="$pubTool.UPLOADVIDEOFORMAT"
? ? ? ? ? ? ? ? ? ? ? ? ?:auto-upload="false"
? ? ? ? ? ? ? ? ? ? ? ? ?:show-file-list="false"
? ? ? ? ? ? ? ? ? ? ? ? ?:limit="1"
? ? ? ? ? ? ? ? ? ? ? ? ?:on-exceed="(files) => { selectedFileMore(files, 'video', 'script_filePath', 1,1, 1, 'script_fileCover', true); addVideo(); }"
? ? ? ? ? ? ? ? ? ? ? ? ?:on-change="(file) => { selectedFile(file, 'video', 'script_filePath', 1, 1,1, 'script_fileCover', true); addVideo(); }">
? ? ? ? ? ? ? ? ? ? ? ? <div>{{item}}</div>
? ? ? ? ? ? ? ? ? ? </el-upload>
? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? ? <div v-if="item=='插入附件'||item=='更換附件'">
? ? ? ? ? ? ? ? ? ? <el-upload class="upload-demo"
? ? ? ? ? ? ? ? ? ? ? ? ? action=""
? ? ? ? ? ? ? ? ? ? ? ? ? :accept="$pubTool.UPLOADSCRIPTFORMAT"
? ? ? ? ? ? ? ? ? ? ? ? ??:auto-upload="false"
? ? ? ? ? ? ? ? ? ? ? ? ??:show-file-list="false"
? ? ? ? ? ? ? ? ? ? ? ? ? :limit="1"
? ? ? ? ? ? ? ? ? ? ? ? ?  multiple
? ? ? ? ? ? ? ? ? ? ? ? ? ?:on-exceed="(files) => { selectedFileMore(files, 'annex', 'script_filePath', 4,1, 1, 'script_fileCover', true); addAnnex(); }"
? ? ? ? ? ? ? ? ? ? ? ? ? ?:on-change="(file) => { selectedFile(file, 'annex', 'script_filePath', 4, 1,1, 'script_fileCover', true); addAnnex(); }">
? ? ? ? ? ? ? ? ? ? ? ? <div>{{item}}</div>
? ? ? ? ? ? ? ? ? ? </el-upload>
? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? ? <div v-if="item=='插入鏈接'||item=='更換鏈接'" @click="operHref.ifShow = true">
? ? ? ? ? ? ? ? ? ? {{item}}
? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? ? <div v-if="item=='清空單元格'" @click="clearCell">
? ? ? ? ? ? ? ? ? ? {{item}}
? ? ? ? ? ? ? </div>
? ? ? ?</div>
</div>

js代碼

data() {
? ? ? ? ? ? return {
? ? ? ? ? ?
? ? ? ? ? ? ? ? visible: false,//菜單隱藏控制
? ? ? ? ? ? ? ? td_index: 0,//當(dāng)前點擊的單元格列下標(biāo)
? ? ? ? ? ? ? ? tr_index: 0,//當(dāng)前點擊的單元格行下標(biāo)
? ? ? ? ? ? ? ? top: 0,
? ? ? ? ? ? ? ? left: 0,
? ? ? ? ? ? ? ? menuList: ["插入圖片", "插入視頻", "插入鏈接", "插入附件", "更換圖片", "更換視頻", "更換鏈接", "更換附件", "清空單元格"],
? ? ? ? ? ??
? ? ? ? ? ? }
? ? ? ? },
? ? ? ? watch: {
? ? ? ? ? ? //監(jiān)聽visible的變化,來觸發(fā)關(guān)閉右鍵菜單,調(diào)用關(guān)閉菜單的方法
? ? ? ? ? ? visible(value) {
? ? ? ? ? ? ? ? if (value) {
? ? ? ? ? ? ? ? ? ? document.body.addEventListener('click', this.closeMenu)
? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? ? document.body.removeEventListener('click', this.closeMenu)
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? },
? ? ? ? ?//鼠標(biāo)右鍵事件--打開菜單
? ? ? ? ? ? openMenu(e, item, td_index, tr_index) {
? ? ? ? ? ? ? ? if (item.ifR || this.action == 'detail' || this.action == 'version' || item.cU == 1) return;
? ? ? ? ? ? ? ? if (item.ifR == 0 && item.cT == 22860 && item.cV.cD) this.menuList = ["清空單元格"];
? ? ? ? ? ? ? ? if (item.ifR == 0 && item.cT == 22861 && item.cV.cD) this.menuList = ["更換圖片", "清空單元格"];
? ? ? ? ? ? ? ? if (item.ifR == 0 && item.cT == 22862 && item.cV.cD) this.menuList = ["更換視頻", "清空單元格"];
? ? ? ? ? ? ? ? if (item.ifR == 0 && item.cT == 22863 && item.cV.cD) this.menuList = ["更換鏈接", "清空單元格"];
? ? ? ? ? ? ? ? if (item.ifR == 0 && item.cT == 22864 && item.cV.cD) this.menuList = ["更換附件", "清空單元格"];
? ? ? ? ? ? ? ? if (item.ifR == 0 && (item.cT == 22860 || item.cT == 22861 || item.cT == 22862 || item.cT == 22863 || item.cT == 22864) && item.cV.cD == '') this.menuList = ["插入圖片", "插入視頻", "插入鏈接", "插入附件", "清空單元格"];
? ? ? ? ? ? ? ? //this.rightClickItem = item;
? ? ? ? ? ? ? ? let x = e.clientX;
? ? ? ? ? ? ? ? let y = e.clientY;
? ? ? ? ? ? ? ? this.top = y;
? ? ? ? ? ? ? ? this.left = x;
? ? ? ? ? ? ? ? this.td_index = td_index;
? ? ? ? ? ? ? ? this.tr_index = tr_index;
? ? ? ? ? ? ? ? this.visible = true;
? ? ? ? ? ? },
? ? ? ? ? ? //鼠標(biāo)右鍵事件--關(guān)閉菜單
? ? ? ? ? ? closeMenu() {
? ? ? ? ? ? ? ? this.visible = false;
? ? ? ? ? ? },

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue中常見的幾種傳參方式小結(jié)

    Vue中常見的幾種傳參方式小結(jié)

    Vue組件的使用不管是在平常工作還是在面試面試中,都是頻繁出現(xiàn)的,下面這篇文章主要給大家介紹了關(guān)于Vue中常見的幾種傳參方式的相關(guān)資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2023-05-05
  • 最新評論