[Vuejs]-Why isn't the prop defined?

0๐Ÿ‘

โœ…

I think you are mixin the <script setup> notation (using composition API) with the option API. You can either do :

<script setup>
import { ref, defineProps } from 'vue';

let imgLink = ref()

const props = defineProps({
  name: String,
  imgurl: String
})

fetch(props.imgurl).then(res => res.json()).then(json => imgLink.value = json.sprites.front_default)
</script>

See : https://vuejs.org/api/sfc-script-setup.html#defineprops-defineemits

Or with the options API :

<script>
export default {
    props: {
        'name': String,
        'imgurl': String
    },
    data: () => ({
       imgLink: null,
    }),
    created() {
        fetch(this.imgurl).then(res => res.json()).then(json => this.imgLink = json.sprites.front_default)
    }
}
</script>

Leave a comment