uni-app通过添加class修改样式属性-微信小程序

11 篇文章 1 订阅

实现点击某个元素,则变色的效果;

效果1,默认选中第一个

 效果1代码

<template>
	<view>
		<view>
		</view>
		<view class="list_class" v-for="(item,index) in list" @click="test_click(index)":class="{'list_add_class':num==index}">
			{{item}}
		</view>

	</view>
</template>
<script>
	export default {
		data() {
			return {
				list: ['北京', '上海', '广东', '深圳'],
				num: '',
			}
		},
		methods: {
			test_click(index) {
				this.num = index
			},
		}
	}
</script>
<style>
	.list_class {
		margin-top: 20rpx;
		height: 200rpx;
		width: 780rpx;
		text-align: center;
		line-height: 200rpx;
		background-color: gold;
	}

	.list_add_class {
		background-color: hotpink;
	}
</style>

效果2,默认全部不变色

 效果2代码

<template>
	<view>
		<view>
		</view>
		<view class="list_class" v-for="(item,index) in list" @click="test_click(index)":class="{'list_add_class':num==index}">
			{{item}}
		</view>

	</view>
</template>
<script>
	export default {
		data() {
			return {
				list: ['北京', '上海', '广东', '深圳'],
				num: '这里不等于空,默认都不变色',
			}
		},
		methods: {
			test_click(index) {
				this.num = index
			},
		}
	}
</script>
<style>
	.list_class {
		margin-top: 20rpx;
		height: 200rpx;
		width: 780rpx;
		text-align: center;
		line-height: 200rpx;
		background-color: gold;
	}

	.list_add_class {
		background-color: hotpink;
	}
</style>

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
uni-app中实现微信小程序的一键登录功能,需要使用button组件的open-type开放能力。在button标签中设置open-type为"getUserInfo",并通过@getuserinfo事件来触发wxLogin方法。具体代码如下: <button type="default" open-type="getUserInfo" @getuserinfo="wxLogin">一键登录微信小程序</button> 在App.vue文件中,可以配置小程序的全局样式、生命周期函数等。manifest.json文件用于配置应用名称、appid、logo、版本等打包信息。pages.json文件用于配置页面路径、页面窗口样式、tabBar、navigationBar等页面类信息。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [uni-app实现微信小程序一键登录](https://blog.csdn.net/qq_45797421/article/details/118339987)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [uni-app实现购物商城的微信小程序,优秀毕业设计源代码,小白必看!](https://download.csdn.net/download/qq_42257666/87667930)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值