位置:首页 » 文章/教程分享 » 微信小程序中具体写到几种常见的弹框提示信息和跳转页面的组件

本文介绍在微信小程序中具体写到几种常见的弹框提示信息和跳转页面的组件,有相关需求的朋友赶紧看看吧。

第一种模态窗口:

wx.showModal

/**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    wx.showModal({
      title: '提示',
      content: '这是一个模态窗口',
      success:function(res){
            if(res.confirm){
              console.log('弹框后点取消')
            }else{
                console.log('弹框后点取消')
            }
      }
    })
  },
第二种提示你想提示的信息。不带确定和取消按钮。可以用在判断注册成功或失败的验证。
wx.showToast

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
   wx.showToast({
     title:'成功',
     icon:'success',
     duration:2000
   })
  },

第三种弹框的时候如果icon:none只是提示title里的文字不会有样式的弹框显示。

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   wx.showToast({
     title: '加载中',
     icon:'loading',
     duration:10000
 })
  setTimeout(function(){
   wx.hideToast()
   },2000)
 
  },
关闭当前页面,跳转到应用内的某个页面。
wx.redirectTo(OBJECT)
wx.redirectTo({
  url: '../index/index',
})