vue点击编辑按钮,内容变成input可以修改,也可以删除
一、效果
图1

图2,点击报错之后,又变成图1的效果

二、使用到了element UI中的以下组件:
<el-button>
<el-input>
三、使用的关键点是vue中的v-if指令
四、关键代码如下
HTML部分
<div class="content-wrapper">
<div>
<el-button type="primary" icon="el-icon-plus" @click.stop="handleShowDialog(0)">添加街道</el-button>
<el-button type="primary" icon="el-icon-edit" @click.stop="handleEditStreet">编辑</el-button>
<el-button type="primary" icon="el-icon-setting" @click.stop="handleSaveStreet">保存</el-button>
</div>
<div class="street-wrapper">
<template v-for="(item, index) in streetsData">
<el-button v-if="!isEditStreet" :type="activeButton === index ? 'primary' : 'info'" :key="index"
@click.stop="handleButtonClick(index)">{{item.name}}</el-button>
<el-input v-else-if="isEditStreet" :key="index" v-model="item.name" style="width:300px;margin-right:5px;margin-bottom:5px;">
<i slot="append" class="remove el-icon-remove"></i>
</el-input>
</template>
</div>
</div>
JS部分
<script>
export default {
name: 'official',
data () {
return {
activeButton: 0,
dialogTitle: '添加街道', // 控制弹出框title的变量
dialogVisible: false, // 弹出框显示隐藏的控制变量
isAddStreet: true, // true表示是添加街道数据,false表示添加的是社区工作站的数据
streetNameOrCommunityName: '', // 添加的时候用于保存街道的名称获取社区工作站的名称
isEditStreet: false, // 编辑街道
isEditCommunity: false, // 编辑社区
streetsData: [
{id: 1, name: '观湖街道'},
{id: 1, name: '民治街道'},
{id: 3, name: '观澜街道'},
{id: 4, name: '龙华街道'},
{id: 5, name: '大浪街道'},
{id: 6, name: '福城街道'}
],
communityData: [
]
}
},
methods: {
handleButtonClick (index) {
this.activeButton = index
},
/**
* flag:0表示添加街道,1表示添加社区
*/
handleShowDialog (flag) {
this.isAddStreet = !flag
this.dialogTitle = flag ? '添加社区工作站' : '添加街道'
this.$nextTick(() => {
this.dialogVisible = true
})
},
addStreetOrCommunity () {
// 校验输入的内容不能为空
if (!this.streetNameOrCommunityName.length) {
this.$message.error('填写的名称不能为空或者空字符串')
return
}
// 1.校验一下当前添加的街道名称是否已经存在??街道名称是唯一的
// 2.添加成功之后,关闭弹出框,并且要重新请求数据
if (this.isAddStreet) {
// 调用添加街道的接口
this.streetsData.push({id: 10, name: this.streetNameOrCommunityName})
} else {
// 调用社区工作站的接口
this.communityData.push({id: 10, name: this.streetNameOrCommunityName})
}
// 清空streetNameOrCommunityName的数据,避免下次添加的时候显示上次的数据
this.streetNameOrCommunityName = ''
this.dialogVisible = false
},
handleBeforeClose (done) {
this.dialogVisible = false
done()
},
handleEditCommunity () {
this.isEditCommunity = true
},
handleSaveCommunity () {
this.isEditCommunity = false
},
handleEditStreet () {
this.isEditStreet = true
},
handleSaveStreet () {
this.isEditStreet = false
},
enterSystem () {
this.$router.push('/dashboard')
}
}
}
</script>
vue点击编辑按钮,内容变成input可以修改,也可以删除的更多相关文章
- bootstrap-table:操作栏点击编辑按钮弹出模态框修改数据
核心代码: columns: [ { checkbox:true //第一列显示复选框 }, ... { field: 'fail_num', title: '失败数' }, { field: 'op ...
- 用vue实现点击编辑按钮将li变为可以输入文本的input
<template> <li v-if='flag'><span @click='edit()'>点击一下</span></li> < ...
- ElementUI table 点击编辑按钮进行编辑实现示例
<!DOCTYPE html> <html > <head> <meta charset="UTF-8"> <meta nam ...
- vue 点击一个div,使input获得焦点
<div class="inputMessage" @click="inputMessage">输入留言</div> <input ...
- 点击编辑table变为可编辑状态
简单描述:开发中遇到一个小困难,table展示的数据,需要是可编辑的,点击编辑按钮,页面table可以进行编辑,编辑完成后,点击保存数据就保留下来~~~ 思路:用一个带有input的表去替换不带inp ...
- Ubuntu 18.04中截图工具Shutter的编辑按钮不可用的解决办法
Shutter是一个由第三方提供的在Ubuntu上运行的截图工具,相对于系统自带的截图工具(默认可通过Ctrl + Shift + Print快捷键启动截图),最大的优点就是可以即时对图片进行编辑,在 ...
- corethink功能模块探索开发(十四)后台编辑按钮
效果图: 1.添加下图55&58行代码 2.实现edit方法 位于Equip/Admin/DeviceRepaireAdmin.class.php中 public function edit( ...
- vue+element-ui 实现table单元格点击编辑,并且按上下左右键单元格之间切换
通过我的测试我发现两个两种方法来编辑单元格的内容 第一种点击编辑: 我是给td里添加一个input,将值赋值给input,当失去焦点的时候将input的值付给td原来的内容,然后将input删除, 代 ...
- asp.mvc中的vue分页实例,分页组件无法重置reload,解决点击查询按钮后,分页不刷新的问题
刚刚接触Vue.js,现在需要做一个查询功能,并且进行服务端分页.主要思路是在页面中注册一个分页组件,然后进行调用.代码如下 1.引用vue.js,具体去网上下载 2.在html的body中添加如下代 ...
随机推荐
- Java8-Stream-No.01
import java.util.ArrayList; import java.util.List; import java.util.Optional; public class Streams1 ...
- Filtering Approaches for Real-Time Anti-Aliasing(2011 SIGGRAPH)
Filtering Approaches for Real-Time Anti-Aliasing(2011 SIGGRAPH) 在2011的SIGGRAPH上,NVIDA提出了FXAA3.1,本文主要 ...
- BZOJ 2178: 圆的面积并 (辛普森积分)
code #include <set> #include <cmath> #include <cstdio> #include <cstring> #i ...
- element ui的表格列设置fixed后做动态表格出现表格错乱
最近使用element-UI时,使用table做动态表格,当操作列使用fixed时,动态切换表格列设置设置时就会出现错乱,情况如下: 解决方法: 把el-table-column上的key设成一个随机 ...
- hierarchyviewer
支持的版本更低
- @Test 测试
package com.自定义.mall.admin.system; import java.util.List; import java.util.Map; import javax.annotat ...
- 「BZOJ 4565」「HAOI 2016」字符合并「区间状压DP」
题意 给一个长度为\(n(\leq 300)\)的\(01\)串,每次可以把\(k(\leq 8)\)个相邻字符合并,得到新字符和一定分数,最大化最后的得分 题解 考虑设计dp:\(dp[S][i][ ...
- 【线性代数】2-7:转置与变换(Transposes and Permutation)
title: [线性代数]2-7:转置与变换(Transposes and Permutation) toc: true categories: Mathematic Linear Algebra d ...
- bzoj4152
The Captain HYSBZ - 4152 给定平面上的n个点,定义(x1,y1)到(x2,y2)的费用为min(|x1-x2|,|y1-y2|),求从1号点走到n号点的最小费用. Input ...
- 在eclipse中查找一个类中的方法在其他哪个类中被调用了
选中你所要查看的方法名,ctrl+shift+G就可以查看所有调用过该方法的地方了.在Search视图里面可以查看得到这个样子是可以的,你也可以按Ctrl+H全文检索一下