首页 > 解决方案 > 无法在 vue.js 中将数据从 false 更改为 true

问题描述

我试图将我的数据从 false 更改为 true,以便在付款成功时有条件地呈现按钮。在我的 axios 调用中,我收到了作为子对象中的响应的成功,并且可以 console.log 它。但是,有些东西运行不正常,因为付费仍然返回 false。这应该很简单。有任何想法吗?

<template>
  <div>
    <h1>SUCCESS!</h1>
    <button v-if="paid" v-on:click="confirmPayment">Open PDF</button>
  </div>
</template>

<script>
import axios from "axios";

export default {
  name: "Success",
  data() {
    return {
      paid: false,
    };
  },
  mounted() {
    axios.get("http://localhost:5000/pay/confirm").then((res) => {
      console.log(res.data.status);
      if (res.data.status == "succeeded") {
        console.log(res.data.status);
        this.confirmPayment();
      }
      console.log(this.paid);
    });
  },
  methods: {
    confirmPayment() {
      this.paid === true;
    },
    getPDF() {
      axios("http://localhost:5000/pdf", {
        method: "GET",
        responseType: "blob", //Force to receive data in a Blob Format
      })
        .then((response) => {
          const file = new Blob([response.data], { type: "application/pdf" });
          const fileURL = URL.createObjectURL(file);
          window.open(fileURL);
        })
        .catch((error) => {
          console.log(error);
        });
    },
  },
};
</script>

<style scoped>
h1 {
  font-family: "Oswald", sans-serif;
  color: white;
}
</style>

标签: javascriptvue.jsmethodsboolean

解决方案


this.paid === true;

应该this.paid = true;


推荐阅读