Sign in

How does Vue reuse a piece of code in a single file?

pxguf edited in Wed, 31 Aug 2022

For example, I have a code block a that I need to include in a node in some cases

For example, code block a contains dozens of lines

<div v-if="needScroll">

<div v-else>

Is there any easy way to write it? At present, one copy is directly copied up and down. It's a bit messy to change two places

3 Replies
commented on Wed, 31 Aug 2022

Make a component and load code a with slot.

commented on Wed, 31 Aug 2022

Seal code block a as a new component, and all the data needed by code block a will be sent in through props

commented on Thu, 01 Sep 2022


lock This question has been locked and the reply function has been disabled.