I have a Vue component 'FullCart' with a default slot like so:
<template>
<div>
<slot></slot>
</div>
</template>
This is only used to wrap the cart of a Woocommerce site.
<full-cart :key="componentKey">
<form>
<!-- woocommerce cart -->
</form>
</full-cart>
After updating an item in the cart the view updates through AJAX and the old form gets replaced with the contents of the new form. This behaviour is provided by Woocommerce and out of my hands.
By changing the 'componentKey' property, after the new HTML is inserted, the FullCart component is re-rendered and all child components present in the new HTML are rendered by Vue. So far so good. ????
The problem is that, as soon the component re-renders, any input elements (like item quantities) reset to the values before the AJAX call was made. As if Vue wants to reset to the old state. The values of those input elements is non-reactive data, not present in my app.
So to summarize:
- Change item quantity from 2 to 3
- Cart refreshes through AJAX
- New HTML is inserted into the DOM (not the "Vue-way")
- Change componentKey to re-render the component
- Old inputs values are visible.
Does anyone know how to fix this or a way around this?
full-cart
component? – Jamie T