Taro 小程序中使用打开 H5 页面的实现方式

187 阅读1分钟

1. 使用 Taro.navigateTo (推荐)

Taro.navigateTo({
  url: '/pages/webview/index?url=' + encodeURIComponent('https://www.baidu.com')
})

2. 创建 WebView 页面

import { WebView } from '@tarojs/components'
export default function WebViewPage() {
  const { url } = this.$router.params
  return <WebView src={url} />
}

3. 配置路由

在 app.config.js 中添加路由配置:

export default {
  pages: [
    // ...其他页面
    'pages/webview/index'
  ]
}