小程序跳轉(zhuǎn)H5頁(yè)面注意事項(xiàng)

小程序跳轉(zhuǎn)方法如下

submmit(v,data){
                let baseURL = '';
                if(process.env.NODE_ENV === "development"){
                    baseURL = 'https://test-hr.vip56.cn';
                }else{
                    baseURL = 'https://hr.vip56.cn';
                }
                let userName = JSON.parse(wx.getStorageSync('renziUser')).userName;
                let userId = JSON.parse(wx.getStorageSync('renziUser')).id;
                if(v==1){
                    let targetUrl = `${baseURL}/H5/apply/apply.html`;
                    wx.navigateTo({
                        url: `/page_hr/sign/index?method=signIn&Id=${data.trainingClassId}&userName=${userName}&userId=${userId}&targetUrl=${targetUrl}`,
                    })
                }else if(v==2){
                    let targetUrl = `${baseURL}/H5/apply/apply.html`;
                    wx.navigateTo({
                        url: `/page_hr/train/index?method=apply&Id=${data.trainingClassId}&userName=${userName}&userId=${userId}&targetUrl=${targetUrl}`,
                    })
                }else if(v==3){
                    let targetUrl = `${baseURL}/H5/apply/apply.html`;
                    wx.navigateTo({
                        url: `/page_hr/evaluate/index?method=score&Id=${data.trainingClassId}&userName=${userName}&userId=${userId}&targetUrl=${targetUrl}`,
                    })
                }
            }

小程序需要跳轉(zhuǎn)的頁(yè)面如下

<template>
    <web-view :src="targetUrl"></web-view>
</template>

<script>
    export default {
        data() {
            return {
                targetUrl: ''
            }
        },
        onLoad(option){
            this.targetUrl = `${option.targetUrl}?method=${option.method}&Id=${option.Id}&userName=${option.userName}&userId=${option.userId}`;
        }
    }
</script>
<style lang="scss">
page {
  background: #f4f4f4;
}
</style>
<style lang="scss" scoped>
</style>

注意:微信公眾平臺(tái)需要配置H5頁(yè)面url,在開發(fā)管理-開發(fā)設(shè)置-業(yè)務(wù)域名配置H5頁(yè)面的url


image.png

點(diǎn)擊修改后需要下載校驗(yàn)文件


image.png

校驗(yàn)文件下載后放入需要跳轉(zhuǎn)的項(xiàng)目的文件夾中,如wxToken(這個(gè)文件夾是自己新建的),【EDyaXCZ08b.txt】就是校驗(yàn)文件,該文件不用修改
image.png

放入后在跳轉(zhuǎn)項(xiàng)目的文件夾找到build文件夾下的【webpack.dev.conf.js】和【webpack.prod.conf.js】,添加如下代碼:

plugins: [
    new webpack.DefinePlugin({
      "process.env": require("../config/dev.env")
    }),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update.
    new webpack.NoEmitOnErrorsPlugin(),
    // https://github.com/ampedandwired/html-webpack-plugin
    new HtmlWebpackPlugin({
      filename: "index.html",
      template: "index.html",
      inject: true,
      favicon: path.resolve("./src/assets/img/icons.png")
    }),
    // copy custom static assets
    new CopyWebpackPlugin([
      {
        from: path.resolve(__dirname, "../static"),
        to: config.dev.assetsSubDirectory,
        ignore: [".*"]
      },
      {
        from: path.resolve(__dirname, "../H5"),
        to: 'H5',
      },
      {
        from: path.resolve(__dirname, '../wxToken'),
        ignore: ['.*']
      },
    ])
  ]

主要就是

{
        from: path.resolve(__dirname, '../wxToken'),
        ignore: ['.*']
      },
image.png

等該項(xiàng)目發(fā)布完成后,回到微信公眾平臺(tái)的添加業(yè)務(wù)域名的地方添加域名,小程序跳轉(zhuǎn)H5方可完成。

?著作權(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ù)。

相關(guān)閱讀更多精彩內(nèi)容

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