App.vue 1.23 KB
Newer Older
leiqingsong's avatar
leiqingsong committed
1 2
<template>
  <div id="app">
leiqingsong's avatar
leiqingsong committed
3
    <base-nav-bar v-if="!$route.meta.noNav" :navBarTitle="currentTitle" />
leiqingsong's avatar
leiqingsong committed
4 5 6 7
    <router-view />
  </div>
</template>

8 9
<script>
import BaseNavBar from "./components/BaseNavBar.vue";
leiqingsong's avatar
leiqingsong committed
10
import { getUserInfo } from "@/api/user";
11 12 13 14 15 16 17 18 19 20 21 22 23
export default {
  components: {
    BaseNavBar
  },
  data() {
    return {
      currentTitle: ""
    };
  },
  watch: {
    $route(val) {
      this.currentTitle = val.meta.title;
    }
leiqingsong's avatar
leiqingsong committed
24
  },
leiqingsong's avatar
leiqingsong committed
25
  mounted() {
leiqingsong's avatar
leiqingsong committed
26
    console.log("和App开始交互");
leiqingsong's avatar
leiqingsong committed
27 28
    this.$bridgeToAppFun
      .getAuthToken()
leiqingsong's avatar
leiqingsong committed
29 30
      .then(res => {
        console.log("获取token成功", res);
leiqingsong's avatar
leiqingsong committed
31
        this.saveUser(res);
leiqingsong's avatar
leiqingsong committed
32 33 34 35
      })
      .catch(err => {
        console.log("获取token失败", err);
      });
leiqingsong's avatar
leiqingsong committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49
  },
  methods: {
    saveUser(data) {
      if (data) {
        getUserInfo().then(res => {
          console.log("存用户信息");
          if (res.code == 0) {
            localStorage.setItem("user", JSON.stringify(res.data));
          }
        });
      } else {
        console.log("调用失败");
      }
    }
xulili's avatar
xulili committed
50
  }
51 52 53
};
</script>

leiqingsong's avatar
leiqingsong committed
54 55 56
<style lang="scss">
body {
  font-size: 16px;
leiqingsong's avatar
leiqingsong committed
57
  font-family: PingFang-SC-Medium;
leiqingsong's avatar
leiqingsong committed
58 59 60 61 62
  background: #f8f8f8;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
</style>