「小程序JAVA实战」小程序的组件(23)

男娘i 2022-01-12 07:13 341阅读 0赞

转自:https://idig8.com/2018/08/11/xiaochengxu-chuji-23/

开始了解下小程序的组件。源码:https://github.com/limingios/wxProgram.git 中的No.10

组件

  • 多个组件构成一张视图页面

    经过样式和布局,页面其实理解成html

  • 组件包含<开始标签></结束标签>
  • 每个组件都包含一些公用属性
  • 官方的阐述

    https://developers.weixin.qq.com/miniprogram/dev/component/

1240

view视图组件

  • view 组件

    用的最多的,也是之前的样例也讲过。https://developers.weixin.qq.com/miniprogram/dev/component/view.html

1240 1

  • 演示用例


    .container{
    background-color: red;
    }

    .hover-class{
    background-color: gray;
    }

1240 2

scroll-view 视图组件

  • 官网的介绍

    https://developers.weixin.qq.com/miniprogram/dev/component/scroll-view.html

1240 3

1240 4

  • 演示


    a
    b
    c
    d
    e

  1. <scroll-view class="container-nowrap" style='margin-top:250rpx' scroll-x='true' scroll-left="200">
  2. <view id="a" class='sizeX a'>a</view>
  3. <view id="b" class='sizeX b'>b</view>
  4. <view id="c" class='sizeX c'>c</view>
  5. <view id="d" class='sizeX d'>d</view>
  6. <view id="e" class='sizeX e'>e</view>
  7. </scroll-view>
  8. //scroll-view.js
  9. //获取应用实例
  10. Page({
  11. scrolltoupper:function(){
  12. console.log("滚动到顶部");
  13. },
  14. scrolltolower:function(){
  15. console.log("滚动到底部");
  16. },
  17. scroll:function(){
  18. console.log("滚动中。。。");
  19. }
  20. })
  21. .container-wrap{
  22. display: flex;
  23. flex-wrap:wrap;
  24. }
  25. .container-nowrap{
  26. display:flex;
  27. white-space: nowrap;
  28. }
  29. .sizeY{
  30. width: 100%;
  31. height: 150rpx;
  32. }
  33. .sizeX{
  34. width: 250rpx;
  35. height: 150px;
  36. display: inline-block;
  37. }
  38. .a {
  39. background: red;
  40. }
  41. .b {
  42. background: yellow;
  43. }
  44. .c {
  45. background: blue;
  46. }
  47. .d {
  48. background: green;
  49. }
  50. .e {
  51. background: gold;
  52. }

1240 5

注意:enable-back-to-top=”true” 在开发工具没办法演示只能在手机上才能演示出来点击直接到达顶部的效果。关于scrollview 只有横向和纵向,其实这块还是比较重要的多加练习吧。

swiper组件

  • 俗称 轮播图
  • 官方介绍

    https://developers.weixin.qq.com/miniprogram/dev/component/swiper.html

1240 6

1240 7

1240 8

  • 演示

    <swiper indicator-dots=”{

    1. {indicatorDots}}"

    autoplay=”{

    1. {autoplay}}" interval="{
    2. {interval}}" duration="{
    3. {duration}}">

    <block wx:for=”{

    1. {imgUrls}}">
    2. <swiper-item>
    3. <image src="{
    4. {item}}" class="slide-image" width="355" height="150"/>
    5. </swiper-item>





    interval
    duration

    //swiper.js
    //获取应用实例

    Page({
    data: {

    1. imgUrls: [
    2. 'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
    3. 'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
    4. 'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
    5. ],
    6. indicatorDots: false,
    7. autoplay: false,
    8. interval: 5000,
    9. duration: 1000

    },
    changeIndicatorDots: function (e) {

    1. this.setData({
    2. indicatorDots: !this.data.indicatorDots
    3. })

    },
    changeAutoplay: function (e) {

    1. this.setData({
    2. autoplay: !this.data.autoplay
    3. })

    },
    intervalChange: function (e) {

    1. this.setData({
    2. interval: e.detail.value
    3. })

    },
    durationChange: function (e) {

    1. this.setData({
    2. duration: e.detail.value
    3. })

    }
    })

1240 9

image.png

  • 演示




    .container{
    background-color: red;
    width: 100%;
    height: 650rpx;
    }

    .size{
    background-color: yellow;
    width: 300rpx;
    height: 250rpx;
    }

    //movable.js
    //获取应用实例

    Page({
    onchange:function(){

    1. console.log("在移动。。");

    },
    onscale:function(){

    1. console.log("在缩放")

    }
    })

1240 10

PS:跟老铁一起过了一遍wx小程序关于视图的api,感觉还是组件很丰富,很好用!

转载于:https://www.cnblogs.com/sharpest/p/10285513.html

发表评论

表情:
评论列表 (有 0 条评论,341人围观)

还没有评论,来说两句吧...

相关阅读