小程序跳轉(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)的頁面如下
<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掠廓,在開發(fā)管理-開發(fā)設(shè)置-業(yè)務(wù)域名配置H5頁面的url
點(diǎn)擊修改后需要下載校驗(yàn)文件
校驗(yàn)文件下載后放入需要跳轉(zhuǎn)的項(xiàng)目的文件夾中,如wxToken(這個文件夾是自己新建的)汪厨,【EDyaXCZ08b.txt】就是校驗(yàn)文件仓犬,該文件不用修改
放入后在跳轉(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: ['.*']
},
等該項(xiàng)目發(fā)布完成后兄纺,回到微信公眾平臺的添加業(yè)務(wù)域名的地方添加域名废菱,小程序跳轉(zhuǎn)H5方可完成技矮。