I have a problem that I can’t solve.
How can I detect the real-time height change of div1 in Vue3 and obtain the height of div1 minus 12px for div2?
If div1 contains multiple lines of text and its height expands from 100px to 150px, how can I obtain the value of 150px – 12px = 138px for div2 and assign a height of 138px to div2?
I apologize for any confusion caused. English is not my primary language. If you have any questions, please let me know.
Best regards.
I can capture the initial height, but I cannot capture it in real-time when it changes height.
2
Answers
Here is a workaround for your problem. The ResizeObserver calculates the height when the text inside the div changes. To Listen to this event watchEffect is being used to keep track of it. I hope this will work for you. I don’t work on vue but gave it a try similar to react. So, apologize if there is any mistake.
I don’t see the picture!!
Use
MutationObserver
:Preview: https://play.vuejs.org/#eNp1U8uO2zAM/BXWlzjo1mlydOMA3fawhxYFFuhNFz/oRKgtGTKd3YXhfy/1sOMU20MSiRwNOUNmjL52XXIdMEqjY18a2RH0SEN3Ekq2nTYEo1CCDNYP9vclp/LCJwCtHrHWBn+rVg+KhJqgNrqFDZNtGKpKrXqCC8rzhb7L6x4yYJb483ZOtQPlJLV6ylXVoOH8HPkhOZ2dfGkuAnGDNzzo+g659ThBsoZ4TiT01iFkWQYiyomMLAbCXkQLWJDvYrkK8r3O92nVUEK5OSMl/HlktZVU52+NREXPWFK8/WL1rjms3uSaNwO3ECzwgMn+8NfET4ILmiEKX+BnqPWr6NFc0SxSgj+2yj+mx/HW2tTqpJI90ynXDRs8k1fcxzPWwXpOuPnFIfwA88nROCeshx+WqOFVME7bO7oC6n+mJItufs4taq/rVjw4f5tOCmQGdHvG07nIprLjvYv2Q8G7iD7mvLS2TKzsuPPry4vLF8K2a3JCvgEcuaQ1IBNRKC4iKJu870NERA4HVhLs/ZEpXnnqmMPOk+w46U5PTpfHpjCON2smnmwol/b01iDzj2H+6fqv8An2B/gIm+51M933crjr5bCufNytVPHVVQCee4eVe8NbwNxsq31e5OWfs7FzSVl7ZYOuOws6vAcqeKoBxV5a7lM0/QX5snT1