微信小程序?qū)Ш?navigator

2022-05-11 16:09 更新

navigator

基礎(chǔ)庫 1.0.0 開始支持,低版本需做兼容處理

頁面鏈接。

屬性名 類型 默認(rèn)值 說明
target
String self 在哪個目標(biāo)上發(fā)生跳轉(zhuǎn),默認(rèn)當(dāng)前小程序,可選值self/miniProgram
url String   應(yīng)用內(nèi)的跳轉(zhuǎn)鏈接
open-type String navigate 跳轉(zhuǎn)方式
delta Number   當(dāng) open-type 為 'navigateBack' 時有效,表示回退的層數(shù)
app-id
String
  當(dāng)target="miniProgram"時有效,要打開的小程序 appId
path
String
  當(dāng)target="miniProgram"時有效,打開的頁面路徑,如果為空則打開首頁
extra-data
Object
  當(dāng)target="miniProgram"時有效,需要傳遞給目標(biāo)小程序的數(shù)據(jù),目標(biāo)小程序可在 App.onLaunch() ,App.onShow()  中獲取到這份數(shù)據(jù)。
version
version
release 當(dāng)target="miniProgram"時有效,要打開的小程序版本,有效值 develop(開發(fā)版),trial(體驗版),release(正式版),僅在當(dāng)前小程序為開發(fā)版或體驗版時此參數(shù)有效;如果當(dāng)前小程序是正式版,則打開的小程序必定是正式版。
hover-class String navigator-hover 指定點擊時的樣式類,當(dāng)hover-class="none"時,沒有點擊態(tài)效果
hover-stop-propagation
Boolean
false
指定是否阻止本節(jié)點的祖先節(jié)點出現(xiàn)點擊態(tài)
hover-start-time Number 50 按住后多久出現(xiàn)點擊態(tài),單位毫秒
hover-stay-time Number 600 手指松開后點擊態(tài)保留時間,單位毫秒
bindsuccess
String
當(dāng)target="miniProgram"時有效,跳轉(zhuǎn)小程序成功
bindfail
String
當(dāng)target="miniProgram"時有效,跳轉(zhuǎn)小程序失敗
bindcomplete
String
當(dāng)target="miniProgram"時有效,跳轉(zhuǎn)小程序完成


open-type 有效值:

說明 最低版本
navigate 對應(yīng)wx.navigateTo的功能  
redirect 對應(yīng)wx.redirectTo的功能  
switchTab 對應(yīng)wx.switchTab的功能  
reLaunch 對應(yīng)wx.reLaunch的功能 1.1.0
navigateBack 對應(yīng)wx.navigateBack的功能 1.1.0
exit
退出小程序,target="miniProgram"時生效
2.1.0

注:navigator-hover默認(rèn)為{background-color: rgba(0, 0, 0, 0.1); opacity: 0.7;}, <navigator/>的子節(jié)點背景色應(yīng)為透明色

示例代碼:

/** wxss **/
/** 修改默認(rèn)的navigator點擊態(tài) **/
.navigator-hover {
    color:blue;
}
/** 自定義其他點擊態(tài)樣式類 **/
.other-navigator-hover {
    color:red;
}
<!-- sample.wxml -->
<view class="btn-area">
  <navigator url="/page/navigate/navigate?title=navigate" hover-class="navigator-hover">跳轉(zhuǎn)到新頁面</navigator>
  <navigator url="../../redirect/redirect/redirect?title=redirect" open-type="redirect" hover-class="other-navigator-hover">在當(dāng)前頁打開</navigator>
  <navigator url="/page/index/index" open-type="switchTab" hover-class="other-navigator-hover">切換 Tab</navigator>
</view>
<!-- navigator.wxml -->
<view style="text-align:center"> {{title}} </view>
<view> 點擊左上角返回回到之前頁面 </view>
<!-- redirect.wxml -->
<view style="text-align:center"> {{title}} </view>
<view> 點擊左上角返回回到上級頁面 </view>
// redirect.js navigator.js
Page({
  onLoad: function(options) {
    this.setData({
      title: options.title
    })
  }
})


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號