uniapp-form表单(3)--- slider、switch、textarea

文章内容

一、slider滑动选择器

属性说明
属性名类型默认值说明
minNumber0最小值
maxNumber100最大值
stepNumber1步长,取值必须大于 0,并且可被(max - min)整除
disabledBooleanfalse是否禁用
valueNumber0当前取值
activeColorColor各个平台不同,详见下滑块左侧已选择部分的线条颜色
backgroundColorColor#e9e9e9滑块右侧背景条的颜色
block-sizeNumber28滑块的大小,取值范围为 12 - 28
block-colorColor#ffffff滑块的颜色
show-valueBooleanfalse是否显示当前 value
@changeEventHandle完成一次拖动后触发的事件,event.detail = {value: value}
@changingEventHandle拖动过程中触发的事件,event.detail = {value: value}
 使用方法
<template>
	<view class="content">
		<view class="box">
			<view class="text"> slider滑动选择器。 </view>
			<slider step="5" show-value="true"></slider>
			<slider min="1" max="10" value="5" show-value="true"></slider>
			<slider min="1" max="100" value="5" block-size="12" show-value="true"></slider>
			<slider value="50" block-size="12" active-color="yellow" backgroundColor="black" show-value="true" @change="bindsliderchange"></slider>
			<slider value="50" block-size="12" disabled active-color="yellow" backgroundColor="black" show-value="true"></slider>
		<view class="num">
			num:{{num}}
		</view>    
		</view>
		
		
	
	</view>
</template>

<script>
	export default {
		data() {
			return {
				num:0,
				choose:'',
				aaa:`color: red;font-size: .5rem;`
			}
		},
		methods: {
			bindsliderchange(e){
				this.num = e.detail.value
				console.log(this.num);
			}
		}
	}
</script>

<style>
	.content {
		width: 100%;
	}

	.box {
		width: 90%;
		height: 500rpx;
		background-color: white;
		margin: 0 auto;
		margin-bottom: 30px;
	}

	.text {
		background-color: antiquewhite;
		width: 100%;
		text-align: center;
		font-size: 1.2rem;
	}
</style>

二、switch开关选择器

属性说明
属性名类型默认值说明平台差异说明
checkedBooleanfalse是否选中
disabledBooleanfalse是否禁用抖音小程序与飞书小程序不支持
typeStringswitch样式,有效值:switch, checkbox
colorColorswitch 的颜色,同 css 的 color
@changeEventHandlechecked 改变时触发 change 事件,event.detail={ value:checked}
使用方法
<template>
	<view class="content">
		<view class="box">
			<view class="text">switch开关选择器</view>
				<switch checked="true" @change="bindswitchchange" />
				<view v-if="choose===true">
					<text>打开了按钮</text>
				</view>
				<view v-else-if="choose===false">
					<text>关闭了按钮</text>
				</view>
			{{choose}}
			<view>
				<switch checked="true" color="pink"  type="checkbox"/>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				num:0,
				choose:'',
				aaa:`color: red;font-size: .5rem;`
			}
		},
		methods: {
			bindswitchchange(e){
				this.choose=e.detail.value
				console.log(this.choose);
			}
		}
	}
</script>

<style>
	.content {
		width: 100%;
	}

	.box {
		width: 90%;
		height: 500rpx;
		background-color: white;
		margin: 0 auto;
		margin-bottom: 30px;
	}

	.text {
		background-color: antiquewhite;
		width: 100%;
		text-align: center;
		font-size: 1.2rem;
	}
</style>

三、textarea多行输入框

属性说明
属性名类型默认值说明平台差异说明
valueString输入框的内容
placeholderString输入框为空时占位符
placeholder-styleString指定 placeholder 的样式
placeholder-classStringtextarea-placeholder指定 placeholder 的样式类,注意页面或组件的style中写了scoped时,需要在类名前写/deep/抖音小程序、飞书小程序、快手小程序不支持
disabledBooleanfalse是否禁用
maxlengthNumber140最大输入长度,设置为 -1 的时候不限制最大长度
focusBooleanfalse获取焦点在 H5 平台能否聚焦以及软键盘是否跟随弹出,取决于当前浏览器本身的实现。nvue 页面不支持,需使用组件的 focus()、blur() 方法控制焦点
auto-focusBooleanfalse自动聚焦,拉起键盘京东小程序
auto-heightBooleanfalse是否自动增高,设置auto-height时,style.height不生效
fixedBooleanfalse如果 textarea 是在一个 position:fixed 的区域,需要显示指定属性 fixed 为 true微信小程序、百度小程序、抖音小程序、飞书小程序、QQ小程序、快手小程序、京东小程序
cursor-spacingNumber0指定光标与键盘的距离,单位 px 。取 textarea 距离底部的距离和 cursor-spacing 指定的距离的最小值作为光标与键盘的距离App、微信小程序、百度小程序、抖音小程序、飞书小程序、QQ小程序、京东小程序
cursorNumber指定focus时的光标位置微信小程序、App、H5、百度小程序、抖音小程序、飞书小程序、QQ小程序、京东小程序
..............................

 查看更多属性:textarea | uni-app官网 (dcloud.net.cn)

使用方法
<template>
	<view class="content">
		<view class="box">
			<view class="text">textarea多行输入框</view>
				<textarea class="textarea"></textarea>
			<textarea class="textarea" maxlength="10" :placeholder-style="aaa" placeholder="请输入的爱好"></textarea>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				num:0,
				choose:'',
				aaa:`color: red;font-size: .5rem;`
			}
		},
		methods: {

		}
	}
</script>

<style>
	.content {
		width: 100%;
	}

	.box {
		width: 90%;
		height: 500rpx;
		background-color: white;
		margin: 0 auto;
		margin-bottom: 30px;
	}

	.text {
		background-color: antiquewhite;
		width: 100%;
		text-align: center;
		font-size: 1.2rem;
	}
	.textarea{
		width: 90%;
		height: 100rpx;
		border: 2px solid red;
		margin: 0 auto;
		margin-bottom: 15px;
		margin-top: 10px;
	}
</style>

小结

每一个组件都有它独特的特点,在项目中,选着适合的组件可以提高页面的可读性,以及美化性

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

荣在心中度

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值