Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Vue.js 3 SFC Prop

When I use a prop in SFC the prop shows empty, or as you prefer it does not show.

I have an ActionButton.vue file:

<script setup>
defineProps({
    actionButtonOne: {
        type: String
    }
})
</script>

<template>
    <button type="button">{{ actionButtonOne }}</button>
</template>  

And I am importing it to CardElement.vue:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<script setup>
import ActionButton from './ActionButton.vue'

defineProps({
  singleItem: {
    type: String
  }
})
</script>

<template>
          <ul>
            <li>{{ singleItem }} <ActionButton>Remove</ActionButton></li>
          </ul>
</template>

But when I look in the browser, my Buttons are empty, just a rectangle without "Remove" description.
Why is this and what can I do to fix it?

>Solution :

You can directly use slot to pass content or pass a value for the defined prop :

<script setup>
import ActionButton from './ActionButton.vue'

defineProps({
  singleItem: {
    type: String
  }
})
</script>

<template>
          <ul>
            <li>{{ singleItem }} <ActionButton action-button-one="Remove" ></ActionButton></li>
          </ul>
</template>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading