Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

183
Views
Vue3 variable is assigned but never used when trying to pass props to child

Vue newbie here. I'm trying to pass some props from parent to child, but I get the "variable is assigned a value but never used".

Parent:

<template>
  <TextBox :heading="heading1" :body="body1" />
</template>

<script>
import TextBox from "./components/TextBox.vue";
import { ref } from "vue";

export default {
  name: "App",
  components: {
    TextBox,
  },

  setup() {
    const heading1 = ref("Primo titolo");
    const body1 = ref("Primo corpo del testo");
  },
};
</script>

Child:

<template>
<h1>{{ heading }}</h1>
<p>{{ body }}</p>
</template>

<script>
export default {
  name: 'TextBox',
  props: {
    heading: String,
    body: String,
  }
}
</script>

What am I missing? Thank you!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you are using composition API setup function you need to return, or you can use data function from options API :

const { ref } = Vue
const app = Vue.createApp({
  setup() {
    const heading1 = ref("Primo titolo");
    const body1 = ref("Primo corpo del testo");
    return { heading1, body1 }
  },
})
app.component('TextBox', {
  template: `
    <h1>{{ heading }}</h1>
    <p>{{ body }}</p>
  `,
  props: {
    heading: String,
    body: String,
  }
})
app.mount('#demo')
<script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>
<div id="demo">
  <text-box :heading="heading1" :body="body1" />
</div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!