淘寶小程序(商家應(yīng)用)跳轉(zhuǎn)頁(yè)面方法集合

前言

淘寶小程序(商家應(yīng)用)提供了很多跳轉(zhuǎn)的api,比如跳轉(zhuǎn)淘寶店鋪首頁(yè),跳轉(zhuǎn)商品詳情頁(yè)面,跳轉(zhuǎn)BC客服頁(yè)面等等。雖然官方不支持跳轉(zhuǎn)h5頁(yè),但提供了web-view組件以實(shí)現(xiàn)跳轉(zhuǎn)h5功能,以下是本人整理的跳轉(zhuǎn)各種頁(yè)面的方法。

如果有更多方法或整理有誤,歡迎評(píng)論補(bǔ)充指正。

跳轉(zhuǎn)應(yīng)用內(nèi)某個(gè)頁(yè)面

用官方api my.navigateTo

 my.navigateTo({ url: "/pages/home/index" })}

重定向應(yīng)用內(nèi)某個(gè)頁(yè)面

my.redirectTo({ url: '/pages/home/index' })

返回上一頁(yè)

my.navigateBack()

跳轉(zhuǎn)/跳回某個(gè)小程序

跳轉(zhuǎn)某個(gè)小程序 ,需要目標(biāo)小程序appId。

跳轉(zhuǎn)回上一個(gè)小程序,只有從上一個(gè)小程序跳轉(zhuǎn)到當(dāng)前小程序時(shí)才會(huì)調(diào)用成功。

my.navigateToMiniProgram({
    appId: '2017072607907880', //目標(biāo)小程序appId
    extraData: {
        "data1": "test"
    }, //傳遞給目標(biāo)小程序的數(shù)據(jù),目標(biāo)小程序可在 App.onLaunch(),App.onShow() 中獲取到這份數(shù)據(jù)
    path: '', //打開的頁(yè)面路徑,如果為空則打開首頁(yè)
    success: (res) => {
        console.log(JSON.stringify(res))
    },
    fail: (res) => {
        console.log(JSON.stringify(res))
    }
});

 my.navigateBackMiniProgram({
     extraData: {
         "data1": "test"
     }, //傳遞給目標(biāo)小程序的數(shù)據(jù),目標(biāo)小程序可在 App.onLaunch(),App.onShow() 中獲取到這份數(shù)據(jù)
     success: (res) => {
         console.log(JSON.stringify(res))
     },
     fail: (res) => {
         console.log(JSON.stringify(res))
     }
 });

跳轉(zhuǎn)h5頁(yè)

淘寶小程序不支持跳轉(zhuǎn)外部H5頁(yè)面,不過(guò)可以用官方web-view組件實(shí)現(xiàn)跳轉(zhuǎn)H5頁(yè)功能

// webLink/index.axml
<view>
  <web-view src="{{src}}"></web-view>
</view>

// webLink/index.js
Page({
  data: {
    src : ''
  },
  onLoad(props) {
    // 參數(shù)link為h5鏈接
    let {link} = props
    this.setData({
      src: link
    });
  },
});

// utils.js
// 跳轉(zhuǎn)webview頁(yè)面 , url為h5頁(yè)面鏈接
 my.navigateTo({
     url: `/pages/webLink/index?link=${url}`
 });

跳轉(zhuǎn)到淘寶店鋪首頁(yè)

用官方api my.tb.navigateToTaobaoPage ,需要店鋪id

//實(shí)例代碼
my.tb.navigateToTaobaoPage({
    appCode:'shop', //指定打開店鋪?lái)?yè)
    appParams:{
        shopId:"180175726",
        weexShopTab:"shopindexbar",
        weexShopSubTab:"shopindex"
    },
    success: (res) => {
        my.alert({ content: "success - " + res.success })
    },
    fail: (res) => {
        my.alert({ content: "fail - " + res.error })
    }
});

跳轉(zhuǎn)詳情頁(yè)

用官方api my.tb.openDetail ,需要商品id

my.tb.openDetail ({
      itemId: "576308890723", //商品id
      success: (res) => {
        my.alert({ content: "success" });
      },
      fail: (res) => {
        my.alert({ content: "fail - " + res.error });
      },
});

跳轉(zhuǎn)BC客服頁(yè)

跳轉(zhuǎn)到淘寶店鋪客服用api my.tb.openMessage

my.tb.openMessage({
  sellerNick:"商家測(cè)試賬號(hào)", //賣家昵稱,就是淘寶店鋪名稱
  success: (res) => {
    console.log(res);
  },
  fail: (res) => {
   console.log(res);
  },
})
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容