微信小程序api,带代码详解

微信小程序内置api

1、界面

1、wx.showToast(Object object)显示消息提示框

 wx.showToast({
   
       title: '你好',
       icon:"none"
     })

在这里插入图片描述
事件属性

属性 类型 说明
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数
complete function 接口调用结束的回调函数 (成功失败都会调用)

2、wx.hideToast(Object object)隐藏消息提示框
2秒后关闭提示

  setTimeout(() => {
   
     wx.hideToast();
    }, 2000)

3、wx.showModal(Object object)显示模态对话框

  wx.showModal({
   
      title:"需要看广告才能解锁",
      content:"每天试用两次"
    })

在这里插入图片描述

属性 类型 默认值 说明
title string 提示的标题
content string 提示的内容
showCancel boolean true 是否显示取消按钮
cancelText string ‘取消’ 取消按钮的文字 最多4个字符
cancelColor string #000 取消按钮的文字颜色,必须是16进制格式的颜色字符串
confirmText string ‘确定’ 确认按钮的文字,最多4个字符
confirmColor string #576B95 确认按钮的文字颜色,必须是16进制格式的颜色字符串

4、wx.showLoading(Object object) 提示框
需主动调用 wx.hideLoading 才能关闭提示框

wx.showLoading({
   
      title: '加载中。。。'
    })

在这里插入图片描述

setTimeout(() => {
   
      wx.hideLoading();
    }, 2000)

注意:
①wx.showLoading 和 wx.showToast 同时只能显示一个
②wx.showToast 应与 wx.hideToast 配对使用
5、wx.showActionSheet(Object object)显示操作菜单
在这里插入图片描述
在这里插入图片描述

属性 类型 默认值 说明
itemList Array 按钮的文字数组,数组长度最大为
itemColor string #000 按钮的文字颜色
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数
complate function 接口调用结束的回调函数 (成功失败都会调用)

位置api

(1)wx.getLocation(Object object)
作用:获取当前的地理位置、速度。当用户离开小程序后,此接口无法调用。
注意:调用前需要 用户授权 scope.userLocation
在这里插入图片描述
success成功回调函数参数

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值