1
votes

The image I use below are svg component loaded with vue-svg-loader (see app.vue)

I have 2 components parent and child.

  • The parent use the child and display an image from the child with a text.
  • The child can be used without the parent and only display an image.

Both use a named slot to display the image, the issue is I want to pass a named slot from the parent component to the child one, but seems like to not work the way I want with vuejs named slot and start to be very confusing, is there another way to solve this issue ?

Parent.vue

<template>
    <child>
        <label>Text with image</label>
        <slot name="img">
    </child>
<template>

Child.vue

<template>
    <slot name="img">
<template>

App.vue

<template>
    <parent>
        <mySvg slot="img"/>
    </parent>
<template>
<script>
    import mySvg from 'pathToSvg';
    export default {
        components: {
            mySvg,
        }
    }
</script>
1

1 Answers

3
votes

Try this for the Parent component

<template>
<child>
    <label>Text with image</label>
    <slot slot="img" name="img">
</child>
<template>