微信小程序开发之(表单组件的使用)代码篇

微信小程序开发之(表单组件的使用)代码篇目录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.详细代码

index.js
Page({ 
   

  /** * 页面的初始数据 */
  data: { 
   
  //background:image的变量(设置图片的值)
    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

内容包括添加视频播放、轮转图片、多选框、单选框、实时获取输入值、按钮提交输入控件的数据

 
<!--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>
index.wxss
/**index.wxss**/

.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: 100rpx;
  background-color: yellow;
  border:1px solid#fff;
order: 3;
}

.item1{ 
   
  width:100%;
  height: 150rpx;
  background-color: rgb(105, 185, 109);
  border:1px solid#fff;
order: 3;
}
.item2{ 
   
  height: 300px;
  background-color: rgb(153, 172, 211);
  border:1px solid#fff;
order: 3;
}

.item3{ 
   
  
  background-color: rgb(241, 237, 241);
  border:1px solid#fff;
order: 3;
}

3.结果展示

测试展示图

微信小程序开发之(表单组件的使用)代码篇
在这里插入图片描述

在这里插入图片描述

调试信息,看标记部分

在这里插入图片描述

在这里插入图片描述

4.获取资源

【获取资源】

资源链接:资源获取

微信小程序开发之(表单组件的使用)代码篇
【关注微信公众号一起来交流】
微信小程序开发之(表单组件的使用)代码篇

·

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/159875.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • MySQL创建数据库和创建数据表

    MySQL创建数据库和创建数据表MySQL创建数据库和创建数据表MySQL是最常用的数据库,在数据库操作中,基本都是增删改查操作,简称CRUD。在这之前,需要先安装好MySQL,然后创建好数据库、数据表、操作用户。一、数据库操作语言数据库在操作时,需要使用专门的数据库操作规则和语法,这个语法就是SQL(StructuredQueryLanguage)结构化查询语言。SQL的主要功能是和数据库…

    2022年7月24日
    11
  • 常用网络图片url地址「建议收藏」

    常用网络图片url地址「建议收藏」http://www.baidu.com/img/bdlogo.pnghttp://rongcloud-web.qiniudn.com/docs_demo_rongcloud_logo.png

    2022年7月1日
    315
  • mac如何安装pip_mac怎么卸载python

    mac如何安装pip_mac怎么卸载pythonmac下直接安装pip和卸载pip的方法如下:1、pip的安装:输入sudoeasy_installpip就可以安装pip了。验证pip安装是否成功:输入:pip结果找不到文件。尝试输入:pip3-V或者pip3则说明已经安装成功了。2、pip的卸载:输入命令:sudopipuninstallpip然后输入密码后如下图:输入y,回车。即要卸载pip,再次用pip-V或者pip显示已经找不到文件,即卸载成功了。卸载不再做图片演示。注意:输入p

    2022年10月7日
    2
  • windows系统上配置pip国内下载源

    windows系统上配置pip国内下载源

    2021年6月28日
    90
  • 原创小说:城与兽 第一篇章在线阅读_有兽星七十二城的小说

    原创小说:城与兽 第一篇章在线阅读_有兽星七十二城的小说一名身材健壮的男子走在黄昏的海滩上。伴随着夕阳,和阵阵吹拂的海风,男子边双手抱头走边想:“这下完了呀,这是个什么地方呀,我要怎么回家呀,爸妈要怎么办呀。”他无聊的边走边踢着海滩上的石子,时不时往着被夕阳映射得泛红的天空,时不时又看看一望无际的大海,这海平面让它觉得很绝望。踢着踢着,踢到了一颗他踢不动的。“好痛呀。”男子坐在地上揉起了自己的脚。“真是衰到透顶了。衰起来连石子都…

    2022年8月29日
    4
  • python冒泡排序代码和注释_Python 冒泡排序

    python冒泡排序代码和注释_Python 冒泡排序冒泡排序(BubbleSort)也是一种简单直观的排序算法。它重复地走访过要排序的数列,一次比较两个元素,如果他们的顺序错误就把他们交换过来。走访数列的工作是重复地进行直到没有再需要交换,也就是说该数列已经排序完成。这个算法的名字由来是因为越小的元素会经由交换慢慢”浮”到数列的顶端。见下图:方法一:常规实现冒泡排序#方法1#定义一个列表,用于存放数字list=[]whileTrue:#…

    2022年10月16日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号