在vue里怎么做环境的判断?

uniapp框架(vue)打包成web形式在ArkTS运行,需要在具体的vue页面做环境的判断来对不同组件的调用。

HarmonyOS
2024-11-06 10:14:21
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zxjiu

​可以在应用测注册方法传入H5页面。通过传入的方法获取到信息来判断是否是ArkTS运行。参考地址:​https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/web-in-page-app-function-invoking-V5

如下提供了一个demo示例,可以将getParam1 也就是’ArkTS’这个参数注册传入H5页面,需要先执行registerJavaScriptProxy,再执行refresh操作。再次点击H5页面按钮,传入即可获取到 ‘ArkTS’ 。​

import web_webview from '@ohos.web.webview' 
 
class Params { 
  private param1: string = 'ArkTS' 
 
  constructor() { 
  } 
 
  getParam1() { 
    return this.param1 
  } 
} 
 
 
@Entry 
@Component 
struct ParamsIndexPage { 
  @State message: string = 'Hello World'; 
  controller: web_webview.WebviewController = new web_webview.WebviewController(); 
  private pageParams: Params = new Params() 
 
  build() { 
    Row() { 
      Column() { 
        Web({ src: $rawfile('params_index.html'), controller: this.controller }) 
          .javaScriptAccess(true) 
          .zoomAccess(false) 
          .aspectRatio(1) 
          .margin('3.3%') 
          .padding(20) 
 
        Button('注册方法传参给H5页面') 
          .onClick(() => { 
            this.controller.registerJavaScriptProxy(this.pageParams, "objName", ['getParam1']); 
          }) 
 
        Button('refresh') 
          .onClick(() => { 
            this.controller.refresh(); 
          }) 
 
      } 
      .height('100%') 
    } 
    .width('100%') 
  } 
}
<!DOCTYPE html> 
  <html> 
  <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1.0" charset="utf-8"> 
  <title>带参数传入页面</title> 
  </head> 
  <body> 
  <div> 
  <h1>带参数传入页面 Demo</h1> 
  <button onclick="myFunction()">点击</button> 
  </div> 
  <script> 
  function myFunction() { 
    let params = objName.getParam1() ; 
    alert("Hello World +"+params); 
  } 
 
  </script> 
  </body> 
  </html>
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
分享
微博
QQ
微信
回复
2024-11-06 15:32:43


相关问题
fetch 怎么做超时处理?
988浏览 • 1回复 待解决
后台录像需要怎么做呢?
4627浏览 • 1回复 待解决
请问怎么做MySQL数据优化?
2732浏览 • 2回复 待解决
鸿蒙OTA升级要怎么做
3469浏览 • 0回复 待解决
HarmonyOS 跨设备数据迁移怎么做
470浏览 • 1回复 待解决
HarmonyOS 图片怎么做高斯模糊效果
520浏览 • 1回复 待解决
polarDB私有化部署怎么做
4171浏览 • 1回复 待解决
三表连表查询+groupby怎么做
2498浏览 • 1回复 待解决
应用侧显示华为云mqtt数据是怎么做
7534浏览 • 1回复 待解决
MQTT 服务器 怎么做压力测试,求指导?
4384浏览 • 1回复 待解决