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中添加如下代 ...
随机推荐
- [Svelte 3] Use DOM events and event modifiers in Svelte 3
The whole magic of webapps is that users can interact with our code via various DOM events and Svelt ...
- PHP mysqli_fetch_object() 函数
定义和用法 mysqli_fetch_object() 函数从结果集中取得当前行,并作为对象返回. 注释:该函数返回的字段名是区分大小写的. <?php // 假定数据库用户名:root,密码: ...
- Navicat创建连接
https://blog.csdn.net/suprezheng/article/details/90037702 以下是不用创建直接可用的
- 【csp模拟赛4】 珠江夜游 (cruise.cpp)-二分,贪心
Problem 1 珠江夜游 (cruise.cpp) [题目描述] 小 Z 放假后难得来一趟广州游玩,当然要吃遍广州各路美食小吃然后再 到珠江新城看看远近闻名的小蛮腰啦!可当小 Z 一路吃吃吃以后, ...
- Eclise快捷键(最全)
Eclipse常用快捷键 Eclipse常用快捷键 1几个最重要的快捷键 代码助手:Ctrl+Space(简体中文操作系统是Alt+/) 快速修正:Ctrl+1 单词补全:Alt+/ 打开外部Java ...
- CountDownLatch和CylicBarrier以及Semaphare你使用过吗
CountDownLatch 是什么 CountDownLatch的字面意思:倒计时 门栓 它的功能是:让一些线程阻塞直到另一些线程完成一系列操作后才唤醒. 它通过调用await方法让线程进入阻塞状态 ...
- MySQL-UDF和MOF提权
MOF提权 MOF文件是mysql数据库的扩展文件(在c:/windows/system32/wbem/mof/nullevt.mof) 叫做”托管对象格式”,其作用是每隔五秒就会去监控进程创建和死亡 ...
- 网络编程udp入门
老师布置的作业 echo4_server.c #include<stdio.h> #include<stdlib.h> #include<string.h> #in ...
- 第十四周课程总结&实验报告(简单记事本的实现)
1.JDBC概述 JDBC提供了一种与平台无关的用于执行SQL语句的标准JavaAPI,可以方便的实现多种关系型数据库的统一操作,它由一组用Java语言编写的类和接口组成 主要常用操作类与接口: ja ...
- Qt应用Redis实现消息队列
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/liulihuo_gyh/article/details/78425763 类似BS模式,客户端发 ...