zoukankan      html  css  js  c++  java
  • 内嵌H5与原生app的交互,函数的相互调用

    判断是否是原生
    isNative() {
          let equipmentType = "";
          let agent = navigator.userAgent.toLowerCase();
          let android = agent.indexOf("android");
          let iphone = agent.indexOf("iphone");
          let ipad = agent.indexOf("ipad");
          if (android != -1) {
            equipmentType = "android";
          }
          if (iphone != -1 || ipad != -1) {
            equipmentType = "ios";
          }
          return equipmentType;
        },

        //跳转原生 其中跳转方法需与原生沟通

        goNative(val) {
          let params = {
            pageType: val,
            startTime: this.startTime+' 00:00:00',
            endTime: this.endTime+' 23:59:59',
          };
          if (this.isNative() === "android") {
            console.log("android", JSON.stringify(params));
            window.android.jumpPage(JSON.stringify(params));
          } else if (this.isNative() === "ios") {
            console.log("ios111", JSON.stringify(params));
            window.webkit.messageHandlers.jumpPage.postMessage(JSON.stringify(params));
          }
        },

    当app调用vue中的方法不生效时:在app端内嵌页面中调用vue中的函数时,拿不到methods中定义的函数,需要将Vue项目methods中的方法在mounted中暴露在window上

    APP端调用咱们的方法都是绑定在window上面的方法,故咱们应该讲咱们的方法暴露在window上面,因为Vue项目中的this指向vue,而不是window

      mounted() {
        window["appPushToken"] = (userInfo) => {
          this.AppInfo = userInfo;
          //判断是不是APP端
          if (this.AppInfo) {
            this.AppInfoPlatform = true;
          } else {
            this.AppInfoPlatform = false;
          }
          this.appShare('1')
        };
        window['shareInfo'] = () => {
            this.shareInfo()
         }
      },
     
  • 相关阅读:
    Docker 中国官方镜像加速
    mysql主从同步
    hadoop相关
    Mac上Ultra Edit的激活
    ansible安装应用软件
    Docker学习第二天-容器
    wwnjld团队第二轮迭代成员分数
    第二轮迭代发布报告
    wwnjld第二轮迭代测试报告
    12.24会议记录
  • 原文地址:https://www.cnblogs.com/zjz666/p/14412420.html
Copyright © 2011-2022 走看看