简体   繁体   中英

Vue JS | Component transfering

Wanna transfer component as variable.

For example: We have 3 components: A,B,C.

A.vue

<template>
<B>:redirect_object=C</B>
</template>
<script>
import B from "B";
import C from "C";
export default {
    name: "A",
    components: {B,C}
}
B.vue
...
<script>
export default {
    name: "C"
}

C.vue

 ... <script> export default { name: "C" }

So. I want transfer C.vue component through A.vue to B.vue into redirect_object variable in props .

Tried to import C component in A, but I can't transfer it to B.

Why should you do this? I think it's not a good practice to transfer components like this. The general approach with components is to import components in components (parent - child ) and to dynamically load components with :is attribute.

Docs with examples for dynamic components

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM