当前位置:网站首页>uniapp组件之选择选项(如套餐选择)
uniapp组件之选择选项(如套餐选择)
2022-07-29 05:10:00 【薇森】
功能效果:

代码如下:
<template>
<view class="text-data">
<view class="text-item" v-for="(item, index) in list" :key='index' @click="clicktab(index)" :class="{active:activeindex===index}">
<view>
<!-- 点击后改变图片 -->
<image :src="activeindex===index? '../../static/img/2.png' : '../../static/img/1.png'"></image>
</view>
<view>
{
{item.name}}
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
list:[
{name:'套餐1'},
{name:'套餐2'},
{name:'套餐3'},
],
// 默认没有选中任何一个,为0,则默认选中第一个
activeindex: -1,
}
},
methods: {
clicktab(index){
// 可以选中后取消(这里index为选择的第几个子项索引)
this.activeindex = this.activeindex==index?-1:index;
// this.activeindex = index; 选中后不能取消
}
}
}
</script>
<style lang="scss">
.text-data{
display: flex;
flex-direction: row;
height: 80px;
margin-top: 20px;
justify-content: space-between;
.text-item{
margin-left: 20rpx;
margin-right: 20rpx;
height: 80px;
width: 120px;
border: 1px #d4d4d4 solid;
display: flex;
image{
height: 20px;
width: 20px;
}
// 点击后样式改变
&.active{
color: #ff0000;
background-color: #faf8f4;
border:1px #808270 solid;
}
}
}
</style>边栏推荐
- 【C语言系列】— 字符串+部分转义字符详解+注释小技巧
- C language file operation
- Integer overflow and printing
- Detailed explanation of exit interrupt
- 阿里云张新涛:异构计算为数字经济提供澎湃动力
- Solution: find the position of the first and last element in a sorted array (personal notes)
- Provincial and urban three-level linkage (simple and perfect)
- Wechat applet video upload component is directly uploaded to Alibaba cloud OSS
- 个人学习笔记
- 相对定位和绝对定位
猜你喜欢
随机推荐
Cmu15-213 malloc lab experiment record
href与src的区别
About local variables
【JS题解】牛客网JS篇1-10题
ClickHouse学习(三)表引擎
VIM editor use
实现简单的数据库查询(不完整)
浅谈Servlet
C language file operation
Occt learning 002 - environment construction
167. Sum of two numbers II - enter an ordered array
阿里云联合鼎捷软件发布云上数字工厂解决方案,实现云MES系统本地化部署
数组学习之入门简单题 两数之和
·来一篇编程之路的自我介绍吧·
Cryengine Technology
弹性盒子相关知识
C language first level pointer
Clickhouse learning (VIII) materialized view
End of document
ClickHouse学习(六)语法优化








