小程序跳转H5页面注意事项

2022-03-23  本文已影响0人  小哪吒

小程序跳转方法如下

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}`,
                    })
                }
            }

小程序需要跳转的页面如下

<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>

注意:微信公众平台需要配置H5页面url,在开发管理-开发设置-业务域名配置H5页面的url


image.png

点击修改后需要下载校验文件


image.png
校验文件下载后放入需要跳转的项目的文件夹中,如wxToken(这个文件夹是自己新建的),【EDyaXCZ08b.txt】就是校验文件,该文件不用修改
image.png

放入后在跳转项目的文件夹找到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

等该项目发布完成后,回到微信公众平台的添加业务域名的地方添加域名,小程序跳转H5方可完成。

上一篇下一篇

猜你喜欢

热点阅读