<template>
  <view>
    <text> {{ code }}</text>
    <view class="menu">
      <button @click="copyCode" style="background: red">复制code</button>
      <button @click="freshCode" style="background: orange">
        重新获取code
      </button>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      code: "",
    };
  },
  methods: {
    freshCode() {
      let that = this;
      uni.login({
        success(res) {
          that.code = res.code;
        },
      });
    },
    copyCode(e) {
      let that = this;
      uni.setClipboardData({
        data: that.code,
        success(res) {
          console.log(res);
        },
      });
    },
  },
  onLoad(op) {
    this.freshCode();
  },
};
</script>

<style lang="scss" scoped>
.menu {
  display: flex;
  justify-content: space-between;
  button {
    margin-top: 15px;
    width: 40%;
    color: #fff;
  }
}
</style>