vue中点击切换按钮功能之点启用后按钮变为禁用
作者:大师的修炼之路 时间:2023-07-02 16:51:56
实现方法分位三步:
在template中设置2个按钮,通过v-if ,v-show来控制;
data中设置按钮的默认值;
methods中控制点击按钮切换效果。
<template>
<el-table
:data="tableData"
border
style="width: 100%">
<el-table-column
fixed
prop="date"
label="日期"
width="200">
</el-table-column>
<el-table-column
prop="state"
label="状态"
width="150">
</el-table-column>
<el-table-column
prop="name"
label="姓名"
width="120">
<template slot-scope="scope">
<el-input placeholder="请输入内容" v-show="scope.row.show" v-model="scope.row.姓名">
</el-input>
<span v-show="!scope.row.show">{{scope.row.姓名}}
</span>
</template>
</el-table-column>
<el-table-column
prop="province"
label="省份"
width="120">
</el-table-column>
<el-table-column
prop="city"
label="市区"
width="120">
</el-table-column>
<el-table-column
prop="address"
label="地址"
width="300"
:show-overflow-tooltip="true" >
</el-table-column>
<el-table-column
prop="zip"
label="邮编"
width="120">
</el-table-column>
<el-table-column
fixed="right"
label="操作"
width="300">
<template slot-scope="scope">
<el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
<el-button @click="scope.row.show =true" type="text" size="small">编辑</el-button>
<el-button @click="scope.row.show =false" type="text" size="small">保存</el-button>
<el-button @click="changeStatus" type="text" size="small" v-if="btnStatus == 0">启用</el-button>
<el-button @click="changeStatus" type="text" size="small" v-show="btnStatus == 1">禁用</el-button>
</template>
</el-table-column>
</el-table>
</template>
<script>
export default {
methods: {
handleClick(row) {
console.log(row);
},
changeStatus(){
this.btnStatus = this.btnStatus === 0 ? 1 : 0;
}
},
data() {
return {
btnStatus: 0,
tableData: [{
date: '2016-05-02',
name: '王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎王小虎',
province: '上海',
city: '普陀区',
address: '上海市普陀区金沙江路 1518 弄上海市普陀区金沙江路 1518 弄',
zip: 200333,
show:true
}, {
date: '2016-05-04',
name: '王小虎',
province: '上海',
city: '普陀区',
address: '上海市普陀区金沙江路 1517 弄',
zip: 200333,
show:true
}]
}
}
}
</script>
另外,注意下,data中,按钮的默认值要放在data下,图1。
不能放在table中,否则会按钮显示不出来,且会报错,图2:Property or method "btnStatus" is not defined on the instance but referenced during render.
这个报错原因是:在template里面或者在方法里面使用了 “btnStatus” ,但是在data里面没有定义。
来源:https://www.cnblogs.com/hellomaster/p/13725340.html
标签:vue,切换,按钮
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
ASP同一站点不同编码程序出现乱码解决办法
2008-11-10 12:08:00
Python编写百度贴吧的简单爬虫
2023-12-06 02:17:56
在ASP.NET 2.0中操作数据之一:创建一个数据访问层
2023-06-24 16:58:54
![](https://img.aspxhome.com/file/2023/6/75526_0s.png)
python读取xml文件方法解析
2021-04-25 03:53:45
JS限制textarea字数
2009-09-28 14:41:00
opencv读取视频并保存图像的方法
2023-02-21 17:30:16
![](https://img.aspxhome.com/file/2023/6/105296_0s.jpg)
自学python的建议和周期预算
2021-10-07 04:38:09
JS实现密码框根据焦点的获取与失去控制文字的消失与显示效果
2024-04-10 10:50:20
详谈python在windows中的文件路径问题
2023-12-16 22:02:34
python manim实现排序算法动画示例
2021-11-10 10:41:58
![](https://img.aspxhome.com/file/2023/5/67865_0s.jpg)
一文彻底理清session、cookie、token的区别
2024-01-02 06:16:29
![](https://img.aspxhome.com/file/2023/6/132376_0s.jpg)
PHP simplexml_import_dom()函数讲解
2023-06-09 19:18:30
![](https://img.aspxhome.com/file/2023/3/55403_0s.png)
如何将 jQuery 从你的 Bootstrap 项目中移除(取而代之使用Vue.js)
2023-07-02 17:08:10
oracle数据库sql的优化总结
2024-01-23 16:05:11
MySQL带你秒懂索引下推
2024-01-15 18:34:42
![](https://img.aspxhome.com/file/2023/2/108912_0s.jpg)
Python实战之实现获取动态图表
2023-10-31 14:03:34
![](https://img.aspxhome.com/file/2023/3/97703_0s.jpg)
Asp WinHttp.WinHttpRequest.5.1 对象使用详解
2012-05-02 10:15:27
Python selenium文件上传方法汇总
2022-12-01 04:47:29
用pytorch的nn.Module构造简单全链接层实例
2022-01-04 00:00:17
python批量提交沙箱问题实例
2023-12-14 07:40:09