【微信小程序】button和image组件的基本使用

✅作者简介:CSDN内容合伙人、阿里云专家博主、51CTO专家博主🏆
📃个人主页:hacker707的csdn博客
🔥系列专栏:微信小程序🥇
💬个人格言:不断的翻越一座又一座的高山,那样的人生才是我想要的。这一马平川,一眼见底的活,我不想要,我的人生,我自己书写,余生很长,请多关照,我的人生,敬请期待💖💖💖

在这里插入图片描述

其他常用组件

button

按钮组件
功能比HTML中的button按钮丰富

image

图片组件
image组件默认宽度约300px、高度约240px

navigator

页面导航组件
类似于HTML中的a链接

button按钮的基本使用

✅通过type属性指定按钮颜色类型

<button>普通按钮</button>
<button type="primary">主色调按钮</button>
<button type="warn">警告按钮</button>

在这里插入图片描述

✅size=“mini” 小尺寸按钮

<button size="mini">普通按钮</button>
<button type="primary" size="mini">主色调按钮</button>
<button type="warn" size="mini">警告按钮</button>

在这里插入图片描述

✅plain 镂空按钮

<button size="mini" plain>普通按钮</button>
<button type="primary" size="mini" plain>主色调按钮</button>
<button type="warn" size="mini" plain>警告按钮 </button>

在这里插入图片描述

image组件的基本使用

✅使用src 指向图片路径

<image src="/images/秦霄贤.png"></image>

在这里插入图片描述

image组件的mode属性

image组件的mode属性用来指定图片的裁剪和缩放模式,常用的mode属性值如下:

mode值说明
scaleToFill(默认值)缩放模式,不保持纵横比缩放图片,使图片的宽高完全拉伸至填满image元素
aspectFit缩放模式,保持纵横比缩放图片,使图片长边能完全显示出来,也就是说,可以完整地将图片显示出来
aspectFill缩放模式,保持纵横比缩放图片,只保证图片的短边能完全显示出来,也就是说,图片通常只在水平或垂直方向是完整的,另一个方向将会发生截取
widthFix缩放模式,宽度不变,高度自动变化,保持原图宽高比不变
heightFix缩放模式,高度不变,宽度自动变化,保持原图宽高比不变

✅使用实例:

<image src="/images/秦霄贤.png" mode="aspectFit"></image>

在这里插入图片描述

<image src="/images/秦霄贤.png" mode="aspectFill"></image>

在这里插入图片描述

<image src="/images/秦霄贤.png" mode="widthFix"></image>

在这里插入图片描述

<image src="/images/秦霄贤.png" mode="heightFix"></image>

在这里插入图片描述

结束语🥇

以上就是微信小程序之button和image组件的基本使用
持续更新微信小程序教程,欢迎大家订阅系列专栏🔥微信小程序
你们的支持就是hacker创作的动力💖💖💖

在这里插入图片描述

  • 222
    点赞
  • 227
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 157
    评论
当然,我很乐意为您提供微信小程序更多的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和组件用法及案例代码,可以查看官方文档。
评论 157
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

hacker707

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

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

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

打赏作者

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

抵扣说明:

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

余额充值