undefinedfix
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">
  <scroll-view>
    代码块A
  </scroll-view>
</div>

<div v-else>
  代码块A
</div>

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
jet_black82
commented on Wed, 31 Aug 2022

Make a component and load code a with slot.

Joey
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

twa
commented on Thu, 01 Sep 2022

http://hcysun.me/vue-design/m...

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