Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Passing Data with Props | Section
Harjoittele
Projektit
Tietovisat & Haasteet
Visat
Haasteet
/
Vue.js Fundamentals and App Development

bookPassing Data with Props

Pyyhkäise näyttääksesi valikon

Components often need to receive data from their parent. In Vue, this is done using props.

Props allow you to pass values into a component as attributes.

<!-- Message.vue -->
<script setup>
defineProps(["text"]);
</script>

<template>
  <p>{{ text }}</p>
</template>

Here, the component expects a text prop.

You can pass data to this component from a parent.

<script setup>
import Message from "./components/Message.vue";
</script>

<template>
  <Message text="Hello from parent" />
</template>

The value is passed into the component and displayed in the template.

Props help you create reusable components that can display different data depending on how they are used.

question mark

Which is the correct way to define and use a message prop in a child component?

Valitse oikea vastaus

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 1. Luku 11

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

Osio 1. Luku 11
some-alt