<script>
export default {
  created() {
    const code = this.getUrlKey("code")
    const hostname = document.location.hostname;
    if(code){
      let params = {}
      params.code = code
      params.hostname = hostname
      this.$store.dispatch("WxLogin", params).then((res) => {
          this.$router.push({ path: "/" });
          // this.$router.push({ path: "/register" });
      }).catch((res) => {
          // console.log(code)
          // this.$router.push({ path: "/login" });
          this.$router.push({ path: "/register" });
      });
    }else{
      // this.$router.push({ path: "/login" });
          this.$router.push({ path: "/register" });
    }
  },
  render: function(h) {
    return h() // avoid warning message
  },
  methods: {
      getUrlKey(name) {
          return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null
      },
  }
}
</script>
