【微信小程序】视图容器和基本内容组件

开发者可以通过运用组件快速搭建出页面结构,上一章也有对组件进行介绍,那么本文牛牛就来带大家学习小程序的组件。
我们可以将组件理解为微信内嵌的标签,它在小程序承担的作用与HTML的标签一致,不过组件的功能更加多样、具体。
事不宜迟,让我们开冲!

一,视图容器类组件

1.1 view

  • 普通视图容器,在微信小程序中,view就相当于HTML中的div标签,属于块级元素

  • view由于其无意义性,经常用来做小程序大体框架的布局

栗子:

如下实现纵向布局
wxml文件

<view class="column">
  <view class="view-1 box"></view>
  <view class="view-2 box"></view>
  <view class="view-3 box"></view>
</view
  • 63
    点赞
  • 81
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 112
    评论
当然,我很乐意为您提供微信小程序更多的API和组件用法及案例代码。以下是我为您准备的微信小程序20个API和组件用法及案例代码: 1. wx.getUserInfo() - 获取用户信息 ``` wx.getUserInfo({ success: function(res) { var userInfo = res.userInfo; var nickName = userInfo.nickName; console.log(nickName); } }) ``` 2. wx.showActionSheet() - 显示操作菜单 ``` wx.showActionSheet({ itemList: ['item1', 'item2', 'item3'], success: function(res) { console.log(res.tapIndex); } }) ``` 3. wx.chooseImage() - 选择图片 ``` wx.chooseImage({ count: 1, sizeType: ['original', 'compressed'], sourceType: ['album', 'camera'], success: function(res) { var tempFilePaths = res.tempFilePaths; console.log(tempFilePaths); } }) ``` 4. wx.getLocation() - 获取地理位置 ``` wx.getLocation({ type: 'wgs84', success: function(res) { var latitude = res.latitude; var longitude = res.longitude; console.log(latitude, longitude); } }) ``` 5. wx.openLocation() - 打开地图 ``` wx.openLocation({ latitude: 23.10229, longitude: 113.3345211, scale: 28, name: 'name', address: 'address' }) ``` 6. wx.getSystemInfo() - 获取系统信息 ``` wx.getSystemInfo({ success: function(res) { var system = res.system; console.log(system); } }) ``` 7. wx.navigateToMiniProgram() - 打开其他小程序 ``` wx.navigateToMiniProgram({ appId: 'appId', path: 'path', extraData: { key: 'value' }, envVersion: 'develop/release', success(res) {} }) ``` 8. wx.createInnerAudioContext() - 创建音频实例 ``` var audioCtx = wx.createInnerAudioContext(); audioCtx.src = 'audio.mp3'; audioCtx.play(); ``` 9. wx.chooseVideo() - 选择视频 ``` wx.chooseVideo({ sourceType: ['album', 'camera'], maxDuration: 60, camera: 'back', success: function(res) { var tempFilePath = res.tempFilePath; console.log(tempFilePath); } }) ``` 10. wx.createVideoContext() - 创建视频上下文 ``` var videoCtx = wx.createVideoContext('video'); videoCtx.play(); ``` 11. wx.createInterstitialAd() - 创建插屏广告实例 ``` var interstitialAd = wx.createInterstitialAd({ adUnitId: 'adUnitId' }) interstitialAd.show(); ``` 12. wx.createRewardedVideoAd() - 创建激励视频实例 ``` var rewardedVideoAd = wx.createRewardedVideoAd({ adUnitId: 'adUnitId' }) rewardedVideoAd.show(); ``` 13. <view> - 视图容器组件 ``` <view class="container"> <text>Hello, world!</text> </view> ``` 14. <text> - 文本组件 ``` <text class="text">Hello, world!</text> ``` 15. <button> - 按钮组件 ``` <button class="button" bindtap="onButtonClick">Click me</button> ``` 16. <input> - 输入框组件 ``` <input class="input" type="text" placeholder="Input something..." bindinput="onInput" /> ``` 17. <image> - 图片组件 ``` <image class="image" src="image.png" mode="aspectFit" /> ``` 18. <swiper> - 滑块视图容器组件 ``` <swiper class="swiper" autoplay="true" interval="5000"> <swiper-item> <image src="image1.png" /> </swiper-item> <swiper-item> <image src="image2.png" /> </swiper-item> </swiper> ``` 19. <scroll-view> - 可滚动视图容器组件 ``` <scroll-view class="scroll-view" scroll-x="true"> <view class="item">item1</view> <view class="item">item2</view> <view class="item">item3</view> </scroll-view> ``` 20. <picker> - 选择器组件 ``` <picker class="picker" mode="date" bindchange="onPickerChange"> <view class="picker-text">{{pickerValue}}</view> </picker> ``` 以上是我为您准备的微信小程序20个API和组件用法及案例代码,希望对您有所帮助。如果您需要更多的API和组件用法及案例代码,可以查看官方文档。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

前端小刘不怕牛牛

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

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

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

打赏作者

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

抵扣说明:

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

余额充值