欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Vue+Element ui實現(xiàn)樹形控件右鍵菜單

 更新時間:2022年07月15日 09:41:09   作者:Советский  
這篇文章主要為大家詳細介紹了Vue+Element ui實現(xiàn)樹形控件右鍵菜單,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Vue+Element ui實現(xiàn)樹形控件右鍵菜單的具體代碼,供大家參考,具體內(nèi)容如下

需求

實現(xiàn)樹形控件右鍵菜單功能,有添加文件、刪除文件、重命名功能

一、按需引入ELEMENTUI組件

按需引入ELEMENTUI組件

二、實現(xiàn)菜單功能

1.TEMPLATE

代碼如下(示例):

<!-- 樹形組件 -->
? <el-tree
? ? ? ? ? ? ? :data="data"
? ? ? ? ? ? ? @node-contextmenu="floderOption"
? ? ? ? ? ? ? @node-click="handleNodeClick"
? ? ? ? ? ? ? node-key="id"
? ? ? ? ? ? >
? ? ? ? ? ? <!-- ?-->
? ? ? ? ? ? ? <span?
? ? ? ? ? ? ? ? class="custom-tree-node"?
? ? ? ? ? ? ? ? slot-scope="{ node, data}"?
? ? ? ? ? ? ? ? style="width:100%"
? ? ? ? ? ? ? >
? ? ? ? ? ? ? ? <i class="el-icon-folder" style="color:#DFBA49;margin-right:59x"></i>
? ? ? ? ? ? ? ? <span style="font-size:15px">{{node.label}}</span>
? ? ? ? ? ? ? </span>
? ? ? ? ? ? </el-tree>
? ? ? ? ? ? <!-- 右鍵菜單欄 -->
? ? ? ? ? ? <div :style="{'z-index':999,'position':'fixed',left:optionCardX + 'px',
? ? ? ? ? ? top: optionCardY + 'px',
? ? ? ? ? ? width:'100px',
? ? ? ? ? ? background:'white','box-shadow':'0 2px 4px rgba(0,0,0,.12),0 0 6px rgba(0,0,0,.04)'}"?
? ? ? ? ? ? v-show="optionCardShow"
? ? ? ? ? ? id="option-button-group">
? ? ? ?<el-button @click="append" class="option-card-button">新建</el-button>
? ? ? ?<el-button @click="remove" class="option-card-button">刪除</el-button>
? ? ? ?<el-button @click="rename" class="option-card-button">重命名</el-button>
</div>

2.JS

代碼如下(示例):

// 右鍵菜單屬性設(shè)置
? ? floderOption(e,data,n,t){
? ? ? this.optionCardShow = false
? ? ? this.optionCardX =e.x
? ? ? this.optionCardY = e.y - 110
? ? ? this.optionData = data
? ? ? this.node = n
? ? ? this.tree = t
? ? ? this.optionCardShow = true
? ? },
? ? // 點擊框外區(qū)域 隱藏菜單
? ? OptionCardClose(event) {
? ? ? var currentCli = document.getElementById("option-button-group");
? ? ? if (currentCli) {
? ? ? ? if (!currentCli.contains(event.target)) { //點擊到了id為option-button-group以外的區(qū)域,就隱藏菜單
? ? ? ? ? this.optionCardShow = false;
? ? ? ? }
? ? ? }
? ? },
? ? // 創(chuàng)建
? ? append() {
? ? ? this.optionCardShow = false
? ? ? this.$prompt('請輸??件名', '提?', { // 彈出框?于輸??件名
? ? ? ? confirmButtonText: '確定',
? ? ? ? cancelButtonText: '取消',
? ? ? ? inputPattern: /^\S{1,10}$/,
? ? ? ? inputErrorMessage: '命名不合法,請重新命名'
? ? ? }).then(({
? ? ? ? value
? ? ? }) => {
? ? ? ? if (this.node.level >= 3) {
? ? ? ? ? this.$message.error("最多只?持三級!")
? ? ? ? ? return false;
? ? ? ? }
? ? ? ? console.log(this.optionData.id);
? ? ? ? const newChild = { // 新建?個?節(jié)點
? ? ? ? ? id: id++,
? ? ? ? ? label: value,
? ? ? ? ? children: []
? ? ? ? };

? ? ? ? // TODO 測試修改
? ? ? ? //測試,在樹形控件下方顯示創(chuàng)建后的內(nèi)容
? ? ? ? const newSet = {
? ? ? ? ? id: id++,
? ? ? ? ? name:value
? ? ? ? }

? ? ? ? console.log(this.optionData.children);
? ? ? ? if (!this.optionData.children) { // 如果當前節(jié)點沒有?節(jié)點,那就新建?個空的?節(jié)點數(shù)組,?來存放新建??件夾
? ? ? ? ? this.$set(this.optionData, 'children', []);
? ? ? ? ? this.$set(this.testData2, 'children', []) //測試,在樹形控件下方顯示創(chuàng)建后的內(nèi)容
? ? ? ? }
? ? ? ? this.optionData.children.push(newChild); // 插?
? ? ? ? this.testData2.push(newSet)
? ? ? ? //同時展開節(jié)點
? ? ? ? if (!this.node.expanded) {
? ? ? ? ? this.node.expanded = true
? ? ? ? }
? ? ? ? this.$message({
? ? ? ? ? type: 'success',
? ? ? ? ? message: '?件夾新建成功!'
? ? ? ? });
? ? ? }).catch(() => {
? ? ? ? this.$message({
? ? ? ? ? type: 'info',
? ? ? ? ? message: '創(chuàng)建失敗'
? ? ? ? });
? ? ? });
? ? },
? ? // 刪除
? ? remove() {
? ? ? this.optionCardShow = false
? ? ? this.$confirm('此操作將永久刪除該?件夾, 是否繼續(xù)?', '提?', {
? ? ? ? confirmButtonText: '確定',
? ? ? ? cancelButtonText: '取消',
? ? ? ? type: 'warning'
? ? ? }).then(() => {
? ? ? ? const parent = this.node.parent;
? ? ? ? const children = parent.data.children || parent.data;
? ? ? ? const index = children.findIndex(d => d.id === this.data.id);
? ? ? ? children.splice(index, 1);
? ? ? ? this.$message({
? ? ? ? ? type: 'success',
? ? ? ? ? message: '刪除成功!'
? ? ? ? });
? ? ? }).catch(() => {
? ? ? ? this.$message({
? ? ? ? ? type: 'info',
? ? ? ? ? message: '已取消刪除'
? ? ? ? });
? ? ? });
? ? },
? ? // 重命名
? ? rename(){
? ? ? console.log(this.node)
? ? ? this.optionCardShow = false
? ? ? this.$prompt('請輸??件名', '提?', {
? ? ? ? confirmButtonText: '確定',
? ? ? ? cancelButtonText: '取消',
? ? ? ? inputPlaceholder: this.node.data.label,
? ? ? ? inputPattern: /^\S{1,10}$/,
? ? ? ? inputErrorMessage: '?件名長度在1到10之間'
? ? ? }).then(({
? ? ? ? value
? ? ? }) => {
? ? ? ? this.node.data.label = value
? ? ? ? this.$message({
? ? ? ? ? type: 'success',
? ? ? ? ? message: '?件夾已重命名!'
? ? ? ? });
? ? ? }).catch(() => {
? ? ? ? this.$message({
? ? ? ? ? type: 'info',
? ? ? ? ? message: '取消輸?'
? ? ? ? });
? ? ? });
? ? },
? ? test(node) {
? ? ? console.log(node.id);
? ? ? this.clickNode = node.id
? ? },
? ? handleNodeClick(item, data) {
? ? ? console.log('item: ',item,'data: ', data);
? ? ? this.test(data)
? ? }

3.STYLE

.folder-box {
height: 100%;
}

.option-card-button {
width: 100%;
margin-left: 0;
font-size: 10px;
border-radius: 0;
}

4.data()

data(){
? ? return{
? ? ? optionCardX:'',
? ? ? optionCardY:'',
? ? ? optionCardShow:false,
? ? ? optionData:[],
? ? ? clickNode:0,
? ? ? node:null,
? ? ? tree:null,
? ? ? data:[{
? ? ? ? id:1,
? ? ? ? label:'圖層樹',
? ? ? }],
? ? ? testData:[
? ? ? ? {
? ? ? ? ? name:'影像'
? ? ? ? },
? ? ? ? {
? ? ? ? ? name:'地形'
? ? ? ? },
? ? ? ? {
? ? ? ? ? name:'模型'
? ? ? ? },
? ? ? ? {
? ? ? ? ? name:'矢量'
? ? ? ? },
? ? ? ],
? ? ? testData2:[
? ? ? ? {
? ? ? ? ? id:0,
? ? ? ? ? name:''
? ? ? ? },
? ? ? ? {
? ? ? ? ? id:1,
? ? ? ? ? name:'圖層樹'
? ? ? ? },
? ? ? ]
? ? }
? },

三、效果圖

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

相關(guān)文章

  • Vue2.0中三種常用傳值方式(父傳子、子傳父、非父子組件傳值)

    Vue2.0中三種常用傳值方式(父傳子、子傳父、非父子組件傳值)

    在Vue的框架開發(fā)的項目過程中,經(jīng)常會用到組件來管理不同的功能,有一些公共的組件會被提取出來。下面通過本文給大家介紹Vue開發(fā)中常用的三種傳值方式父傳子、子傳父、非父子組件傳值,需要的朋友參考下吧
    2018-08-08
  • vue中的inject用法及說明

    vue中的inject用法及說明

    這篇文章主要介紹了vue中的inject用法及說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • 使用webpack搭建vue環(huán)境的教程詳解

    使用webpack搭建vue環(huán)境的教程詳解

    這篇文章主要介紹了使用webpack搭建vue環(huán)境的教程,本文通過實例的形式給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-12-12
  • Element-ui?Dialog對話框基本使用

    Element-ui?Dialog對話框基本使用

    這篇文章主要為大家介紹了Element-ui?Dialog對話框基本使用示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-06-06
  • VUE Error: getaddrinfo ENOTFOUND localhost

    VUE Error: getaddrinfo ENOTFOUND localhost

    這篇文章主要介紹了VUE Error: getaddrinfo ENOTFOUND localhost,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-05-05
  • vue請求本地自己編寫的json文件的方法

    vue請求本地自己編寫的json文件的方法

    這篇文章主要介紹了vue請求本地自己編寫的json文件,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-04-04
  • vue-cli整合vuex的時候,修改actions和mutations,實現(xiàn)熱部署的方法

    vue-cli整合vuex的時候,修改actions和mutations,實現(xiàn)熱部署的方法

    今天小編就為大家分享一篇vue-cli整合vuex的時候,修改actions和mutations,實現(xiàn)熱部署的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-09-09
  • vue3?ref獲取組件實例詳細圖文教程

    vue3?ref獲取組件實例詳細圖文教程

    在Vue3中可以使用ref函數(shù)來創(chuàng)建一個響應式的變量,通過將ref函數(shù)應用于一個組件實例,我們可以獲取到該組件的實例對象,這篇文章主要給大家介紹了關(guān)于vue3?ref獲取組件實例的詳細圖文教程,需要的朋友可以參考下
    2023-10-10
  • Vue簡化用戶查詢/添加功能的實現(xiàn)

    Vue簡化用戶查詢/添加功能的實現(xiàn)

    本文主要介紹了Vue簡化用戶查詢/添加功能的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2023-01-01
  • 解決vue中el-tab-pane切換的問題

    解決vue中el-tab-pane切換的問題

    這篇文章主要介紹了解決vue中el-tab-pane切換的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-07-07

最新評論