当前位置: 首页 > news >正文

uni、js——点击与禁用(不可点击)、动态样式class

案例

在这里插入图片描述
没约满的时间可以点击进行选择,约满的就不能选择了。选择完之后变色变字。
核心思想就是创建一个第三方变量存起来,点击谁就存到第三方,在根据这个进行判断。

代码

<template><view class="content"><view class="list"><block v-for="(item,index) in list" :key="index"><view @click="change(item)" :class="{'item':true,'orangeBg': item.id === checkMonth.id,'garyBg': item.display===0,'blueBg': item.display===1}"><view>{{item.time}}</view><!-- 写法一 --><!-- <view>{{item.id === checkMonth.id?'已选择':item.display == 0?'约满':'可约'}}</view> --><!-- 写法二 --><view v-if="item.id === checkMonth.id">已选择</view><view v-else>{{item.display == 0?'约满':'可约'}}</view></view></block></view></view>
</template><script>export default {data() {return {type: 1,list: [ {id: 1,time: "00:30",display: 1}, {id: 2,time: "01:00",display: 0}, {id: 3,time: "01:30",display: 1}, {id: 4,time: "02:00",display: 1}, {id: 5,time: "02:30",display: 1},{id: 6,time: "03:00",display: 0}],checkMonth: {}, //·选中的年月份}},onLoad(options) {this.type = options.type},methods: {change(item) {if (!item.display) {uni.showToast({title:"不可点击,点击也没效果",icon:'error',duration:400})return}console.log("可点击");this.checkMonth = item //当前选中的模块console.log(this.checkMonth);}}}
</script><style>.list {width: 800rpx;display: flex;align-items: center;flex-wrap: wrap;}.item {width: 200rpx;height: 200rpx;border: 1px solid red;}.grayBg {background-color: #cccccc;}.blueBg {background-color: skyblue;}.orangeBg {background-color: #FE9202;}
</style>

点击与禁用

if (!item.display) {uni.showToast({title:"不可点击,点击也没效果",icon:'error',duration:400})return
}

点击之后,满足禁用条件直接return

动态样式

:class="{'item':true,'orangeBg': item.id === checkMonth.id,'garyBg': item.display===0,'blueBg': item.display===1
}"
值为true的代表,这个样式一直存在【比如该item样式内含宽高等的固定样式】
2、3、4行为 满足条件的即显示对应的样式
http://www.lryc.cn/news/141255.html

相关文章:

  • 分布式技术
  • Consul的简介与安装
  • 微服务框架 go-zero logx 日志组件剖析
  • 基于Java+SpringBoot+Vue前后端分离图书电子商务网站设计和实现
  • C# Winfrom通过COM接口访问和控制Excel应用程序,将Excel数据导入DataGridView
  • Linux-tomcat环境搭建、jpress部署实践、nginx反向代理
  • SQLmap使用
  • 【Flutter】Flutter 使用 infinite_scroll_pagination 实现无限滚动分页
  • python爬虫的js逆向入门到进阶教程文章分享汇总~持续更新
  • 面试常问:水平居中和垂直居中的方法
  • 第七届“蓝帽杯”初赛取证题目分享
  • go语言学习之有关变量的知识
  • 算法通过村第8关【青铜】| 二叉树的经典算法题
  • Open3D 点云均值滤波
  • C语言指针入门详解
  • 软件工程(十四) 设计模式之结构型模式(二)
  • 不解压的方式直接更新jar包内部的内容
  • 软件工程(八) UML之类图与对象图
  • 【Unity3D赛车游戏】【五】Unity中汽车加速效果是如何优化的?
  • 龙智案例:某大型零售企业如何打造高速、现代化的ITSM体系
  • jdk 03.stream
  • “华为杯”研究生数学建模竞赛2018年-【华为杯】C题:对恐怖袭击事件记录数据的量化分析
  • java8的reduce方法
  • Mac发现有的软件不能上网的破解之法
  • 定时检测接口是否正常飞书告警脚本
  • 【MySQL】2、MySQL数据库的管理
  • 8086汇编test指令学习
  • 简单js逆向案例(2)
  • azure data studio SQL扩展插件开发笔记
  • 【二分】搜索旋转数组