微信小程序开发之(表单组件的使用)代码篇目录1.工程目录2.代码3.结果6.获取资源这篇文章介绍微信小程序的表单组件的使用1.工程目录需要改动的文件上图已经标出来了2.代码index.js//index.js//获取应用实例constapp=getApp()Page({onShareAppMessage(){return{title:’cover-view’,path:’page/component/pages/cover-view/cover-view
大家好,又见面了,我是你们的朋友全栈君。
笔者直接上代码,组件的详细介绍参考微信开发者文档:点击查看
1.工程目录
2.详细代码
Page ( {
data: {
background:
[ 'https://res.wx.qq.com/wxdoc/dist/assets/img/0.4cb08bb4.jpg' , 'https://res.wx.qq.com/wxdoc/dist/assets/img/0.4cb08bb4.jpg' , 'https://res.wx.qq.com/wxdoc/dist/assets/img/0.4cb08bb4.jpg' ] ,
indicatorDots: true ,
vertical: false ,
autoplay: false ,
interval: 2000 ,
duration: 500 ,
items: [
{
value: 'USA' , name: '美国' } ,
{
value: 'CHN' , name: '中国' , checked: 'true' } ,
{
value: 'BRA' , name: '巴西' } ,
{
value: 'JPN' , name: '日本' } ,
{
value: 'ENG' , name: '英国' } ,
{
value: 'FRA' , name: '法国' }
] ,
inputValue: '' ,
radioItems: [
{
name: 'USA' , value: '美国' } ,
{
name: 'CHN' , value: '中国' , checked: 'true' }
] ,
} ,
checkboxChange ( e) {
console. log ( 'checkbox发生change事件,携带value值为:' , e. detail. value)
const items = this . data. items
const values = e. detail. value
for ( let i = 0 , lenI = items. length; i < lenI; ++ i) {
items[ i] . checked = false
for ( let j = 0 , lenJ = values. length; j < lenJ; ++ j) {
if ( items[ i] . value === values[ j] ) {
items[ i] . checked = true
break
}
}
}
this . setData ( {
items
} )
} ,
onLoad: function ( options) {
} ,
onReady: function ( ) {
} ,
onShow: function ( ) {
} ,
onHide: function ( ) {
} ,
onUnload: function ( ) {
} ,
onPullDownRefresh: function ( ) {
} ,
onReachBottom: function ( ) {
} ,
onShareAppMessage: function ( ) {
} ,
bindKeyInput: function ( e) {
this . setData ( {
inputValue: e. detail. value
} )
} ,
radioChange ( e) {
const checked = e. detail. value
const changed = {
}
for ( let i = 0 ; i < this . data. radioItems. length; i++ ) {
if ( checked. indexOf ( this . data. radioItems[ i] . name) !== - 1 ) {
changed[ 'radioItems[' + i + '].checked' ] = true
} else {
changed[ 'radioItems[' + i + '].checked' ] = false
}
}
this . setData ( changed)
console. log ( changed)
} ,
tapEvent ( ) {
console. log ( '按钮被点击' )
} ,
submit: function ( e) {
console. log ( e)
}
} )
内容包括添加视频播放、轮转图片、多选框、单选框、实时获取输入值、按钮提交输入控件的数据
< ! -- index. wxml-- >
< view class = "container" >
< view>
< text> hello world < / text>
< checkbox- group bindchange= "checkboxChange" >
< label wx: for = "{
{items}}" wx: key= "{
{item.value}}" >
< view >
< checkbox value= "{
{item.value}}" checked= "{
{item.checked}}" / >
< / view>
< view> {
{
item. name} } < / view>
< / label>
< / checkbox- group>
< / view>
< view class = "item3" >
< form bindsubmit= "submit" >
< custom- comp>
< input name= "name" placeholder= "请输入名字" > < / input>
< switch name= "student" / >
< / custom- comp>
< button form- type= "submit" size= "default" type= "primary" > 提交< / button>
< / form>
< / view>
< view class = "item" >
< view> 实时获取输入值:{
{
inputValue} } < / view>
< input maxlength= "10" bindinput= "bindKeyInput" placeholder= "输入同步到view中" / >
< / view>
< / view>
< view class = "item1" >
< text> radio- group< / text>
< radio- group class = "group" bindchange= "radioChange" >
< view class = "label-2" wx: for = "{
{radioItems}}" >
< radio id= "{
{item.name}}" value= "{
{item.name}}" checked= "{
{item.checked}}" > < / radio>
< label class = "label-2-text" for = "{
{item.name}}" > < text> {
{
item. name} } < / text> < / label>
< / view>
< / radio- group>
< / view>
< view class = "item2" >
< text> swiper image < / text>
< swiper indicator- dots= "{
{indicatorDots}}" sytle= "width:300px"
autoplay= "{
{autoplay}}" interval= "{
{interval}}" duration= "{
{duration}}" >
< block wx: for = "{
{background}}" wx: key= "*this" >
< swiper- item>
< image src= "{
{item}}" class = "slide-image" width= "355" height= "300" / >
< / swiper- item>
< / block>
< / swiper>
< / view>
< view class = "item2" >
< text> video < / text>
< video
id= "myVideo"
src= "http://81.71.14.198/vx/testvx.mp4"
binderror= "videoErrorCallback"
danmu- list= "{
{danmuList}}"
enable- danmu
danmu- btn
show- center- play- btn= '{
{false}}'
show- play- btn= "{
{true}}"
controls
picture- in - picture- mode= "{
{['push', 'pop']}}"
bindenterpictureinpicture= 'bindVideoEnterPictureInPicture'
bindleavepictureinpicture= 'bindVideoLeavePictureInPicture'
> < / video>
< / view>
. container{
height: 100 % ;
width: 100 % ;
background- color: rgb ( 119 , 151 , 221 ) ;
display: flex;
flex- direction: row;
flex- wrap: wrap;
justify- content: space- between;
align- items: center;
}
. item{
width: 100 % ;
height: 100 rpx;
background- color: yellow;
border: 1 px solid#fff;
order: 3 ;
}
. item1{
width: 100 % ;
height: 150 rpx;
background- color: rgb ( 105 , 185 , 109 ) ;
border: 1 px solid#fff;
order: 3 ;
}
. item2{
height: 300 px;
background- color: rgb ( 153 , 172 , 211 ) ;
border: 1 px solid#fff;
order: 3 ;
}
. item3{
background- color: rgb ( 241 , 237 , 241 ) ;
border: 1 px solid#fff;
order: 3 ;
}
3.结果展示
在这里插入图片描述
4.获取资源
资源链接:资源获取
·
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/159875.html 原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...