无法在 vue.js 中将数据从 false 更改为 true
Cant change data from false to true in vue.js
我正在尝试将我的数据从 false 更改为 true,以便在付款成功时有条件地呈现一个按钮。在我的 axios 调用中,我在子对象中收到成功的响应,并且可以 console.log 它。但是,有些事情 运行 不正确,因为 paid 仍然 returns 错误。这应该很简单。有什么想法吗?
<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>
this.paid === true;
应该是this.paid = true;
我正在尝试将我的数据从 false 更改为 true,以便在付款成功时有条件地呈现一个按钮。在我的 axios 调用中,我在子对象中收到成功的响应,并且可以 console.log 它。但是,有些事情 运行 不正确,因为 paid 仍然 returns 错误。这应该很简单。有什么想法吗?
<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>
this.paid === true;
应该是this.paid = true;