uni-app开发(二):基础组件及样式

本文详细介绍了uni-app的开发,涵盖底部导航tabBar、view与text组件、CSS3选择器、flex布局、数据渲染、Class与Style绑定、条件渲染、列表渲染、事件处理器以及属性监听和计算属性的使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

!!!
框架

一、底部导航tabBar

在这里插入图片描述

二、view和text组件

view在这里插入图片描述
text
在这里插入图片描述
!!!
使用Vue.js注意事项

生命周期
data属性

三、CSS3选择器

类选择器:
ID选择器:
奇偶选择器:
在这里插入图片描述

nth-of-type
first-of-type/last-of-type
nth-child

四、flex布局

display:flex
flex-direction:
justyfy-content:
align-items:
flex-shrink:设置是否被压缩

五、数据渲染

.name>view

六、Class与Style绑定

:class
style==>color/font-size/

七、条件渲染

v-if:
v-show:
@tap

框架简介下 官方推荐:template-view


v-else-if

八、列表渲染

循环一维数组
循环二维数组
循环对象
v-for

框架简介下官方建议用block-view

九、事件处理器

@tap:手机上的点击事件建议用此关键字
@click

<template>
	<view>
	<view class="name-font">{{name}}</view>
	<view class="button-box" @tap="clickevent()">点击按钮</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				name:"请点击按钮"
			}
		},
		methods: {
			clickevent:function(){
				this.name="按钮已点击";
			},
		}
	}
</script>

<style>
.button-box{
	background: #09BB07;
	color: #FFFFFF;
	width: 80%;
	margin: auto;
	height: 80upx;
	font-size: 50upx;
	border-radius:30upx;
	border: 1upx solid #EEEEEE;
	display: flex;
	justify-content: center;
	align-items: center;
},
.name-font{
	font-size: 50upx;
	border: 1upx solid #CCCCCC;
	padding: 20upx;
	margin: 20upx;
}
</style>

冒泡事件的解决

<template>
	<view>
		<view class="box-inner" @tap="boxouterevent()">
			外面
			<view class="box-outer" @tap="boxinnerevent()">里面</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				name:"请点击按钮"
			}
		},
		methods: {
			boxinnerevent:function(){
				console.log("点击了里面");
			},
			boxouterevent:function(){
				console.log("点击了外面");
			},
		}
	}
</script>

<style>
.box-inner{
	width: 100%;
	height: 500upx;
	background: #007AFF;
	color: #FFFFFF;
	font-size: 40upx;
	display: flex;
	justify-content: center;
	align-items: center;
}
.box-outer{
	width: 300upx;
	height: 300upx;
	background: #09BB07;
	color: #FFFFFF;
	font-size: 40upx;
	display: flex;
	justify-content: center;
	align-items: center;
}
</style>

以上代码执行时,当点击里面的框框会打印–》点击了里面 + 点击了外面,这就是典型的冒泡事件,要解决此问题只需要将对应的@tap改成@tap.stop即可。

十、监听属性——watch

十一、计算属性 computed

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值