Vue 实现微信提示浏览器转跳功能

<template>
  <div class="main">
    <div :class="show==true ? 'block':'blocks'"></div>
  </div>
</template>

<script>
import Vue from "vue";
import { Popup } from "vant";
import { Cell, CellGroup } from "vant";
import { Dialog } from "vant";

// 全局注册
Vue.use(Dialog);
Vue.use(Cell);
Vue.use(CellGroup);
Vue.use(Popup);
export default {
  props: {
    msg: String
  },
  data() {
    return {
      imgUrl: "./live_weixin.png",
      codeValue: "http://192.168.32.214:8083/HymSon.apk",
      show: false
    };
  },
  mounted() {
    this.downApp();
  },
  methods: {
    downApp() {
      let ua = navigator.userAgent.toLowerCase();

      //Android终端
      let isAndroid = ua.indexOf("Android") > -1 || ua.indexOf("Adr") > -1; //Ios终端
      let isiOS = !!ua.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
      if (isWeixinBrowser()) {
        
        this.show = true;
        this.$router.push({
          path: "/product"
        });
      } else {
        if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
          //Ios
        } else if (/(Android)/i.test(navigator.userAgent)) {
          //Android终端
          window.console.log("这是安卓");

          window.location = this.codeValue;
        }
      }

      function isWeixinBrowser() {
        return /micromessenger/.test(ua) ? true : false;
      }
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style >
.block {
  width: 100%;
  height: 400px;
  background-color: gray;
  background-image: url("/live_weixin.png");//默认路劲为public下
  background-size: 100% 100%;
}
.blocks {
  width: 100%;
  height: 400px;
  background-color: gray;
  background-size: 100% 100%;
}
</style>

posted @ 2020-04-13 17:34  可乐_加冰  阅读(1211)  评论(0编辑  收藏  举报