0๐
โ
I figured that if you want to use $ref
variable inside any method you need to use $enxtTick
to access the variable
Here is the solution:
addToCart() {
if (this.selectedSize > 0) {
let orderData = {
selectedSize: this.selectedSize,
productId: this.product.id,
orderQty: this.orderQty,
};
this.sendOrderRequest(orderData);
} else {
this.openToast("Please Select Size First");
// use the $nextTick this way
this.$nextTick(() => {
// here you can use this.$refs, this.selectedSize, this.orderQty etc
this.$refs.product_size.$el.focus();
});
}
},
Source:stackexchange.com