Currently, I have a modal that pops up with a button on it. Depending on some data coming down, I am changing the text and functionality of the button on the modal. I am using a computed to change the button text and another computed to change the button @click code. If the condition is true, it sets the button's @click code to another javascript method.
I'm finding that as soon the modal gets opened, that function that is supposed to be getting attached to the @click of the button is actually getting called and run. Obviously, this is not what I want.
Vue component HTML code:
<button
variant="primary"
outline
type="button"
@click="continueButtonClick"
>
{{ continueButtonText }}
</button>
Vue component JS code:
computed: {
continueButtonClick() {
let vm = this;
let click = vm.close;
console.log("itemMapText: ", vm.item.itemMapText);
if(vm.item.itemMapText === "map_displayText_viewPriceInCart") {
click = vm.updateCartVue(vm.item.itemId);
}
return click;
},
continueButtonText() {
let vm = this;
let buttonText = "Continue Shopping";
if(vm.item.itemMapText === "map_displayText_viewPriceInCart") {
buttonText = "Remove From Cart";
}
return buttonText;
},
Also, the vm.close does seem to be getting properly attached as that only runs when the button is clicked.
vm = this. You do not need that.