P粉8385635232023-08-15 00:59:21
Yes, of course it is possible to use the same component multiple times in a parent component. Each time you insert it into a template, a new instance of the component is created. So, in your case, your code can be simplified as follows:
<template> <!-- 主要部分 --> <div v-if="!popupFlag"> <C :prop-option="option" /> </div> <!-- 弹出部分 --> <div v-else> <C :prop-option="option" /> </div> </template> ... import C from "C.vue" ...
Or, a simpler way is:
<C :prop-option="popupFlag ? optionForPopup : optionForMain" />
This way, you can efficiently reuse the same component with different options based on popupFlag
.