taro小程序跳转h5页面

taro微信小程序跳转h5页面

项目架构-tarojs+react+sass+微信开发者工具

项目使用taro官网上面的步骤构建起来的项目架构,之后生成微信端的小程序,由于项目与车险有关,需要多个渠道融合在一起,所以避免不了要调用其他端的页面去实现功能,所以涉及到了taro小程序跳转h5的知识

小程序跳转需求需求

在项目中,有为用户提供了各种快捷服务:“门店查询”、“保单下载”、“电子发票”、"报案理赔"等功能,在这里我需要跳转到h5页面。

项目目录结构

具体项目结构请查看taro官网介绍

具体实现

第一步:app.js文件
在此文件中有一个组件对象config配置对象,在里面配置小程序需要跳转的其他h5小程序的appid,获得跳转权限
在这里插入图片描述
第二步:server.js页面组件
在文件方法中写跳转连接地址

//门店查询  
handleStoreInquiry=(e)=>{    
    this.$preload('path', Api.StoreQuery) //这里的path是配置的小程序跳转地址   
    Taro.navigateTo({      url: '/pages/webview/webview'    })  
   }

第三步:在微信开发者工具中,会自动生成webview目录结构,在webview.js中已经为你写好了大致的结构,你只需要将你的url键名变为动态传入的值就可以了。

import Taro, { Component } from '@tarojs/taro'
import { View, WebView } from '@tarojs/components'
/**
 * // NOTE Taro 的 RN 端还未提供 WebView 组件,可以引入原生组件来解决 
 * (备注:Taro v1.2.16 已支持,这块代码还是保留作为演示)
 * 
 * Taro 有开启了 tree shaking,对于未用到的内容编译时会自动去除 
 *  因此可以把相应端的内容都 import 进来,再根据环境进行调用即可 
 * 
 * 另外 1.2.17 版本有提供了统一接口方式 https://nervjs.github.io/taro/docs/envs.html 
 * 可以参考 ./src/pages/user-login 中的实现
 */
 import WebViewRN from './rn'import './webview.scss'
export default class extends Component { 
config = {    navigationBarTitleText: ''  }  
url = '' 
title = ''  
componentWillMount() {    
  this.url = this.$router.preload.path    
  this.title = this.$router.preload.tittle || ''    
  Taro.setNavigationBarTitle({ title: this.title })
}  
componentDidMount() {    
   this.url = this.url    
   console.log(this.url)    
   this.setState({      url: this.url    })  }  
   render() {    
      return (      
         <View className='webview'>        
         	<WebView src={this.url} />      
         </View>    )  }
        }

第四步,在文件webview.wxml中将你的url,也就相当于vue的date数据,在微信小程序页面上使用

<web-view src="{{url}}"></web-view>

就这样,小程序跳转h5页面也就完成了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值