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

124
Views
How to pass prop from parent component in html to component vue

I made this using vue-cli. I have a component called InputField, and I render and mount the component to #app. I know that it will inject the component to the app, but how can I get the "default" value in index.html and access it in InputField.vue? I've tried to add props: "default" but the default value is undefined.

The idea is to get the default value from the component in html and save it to values in data when component is mounted.

I added the following ... ... to my html but seems like it wont work in vue-cli?

Also in my template I added default="def" like this:

<input default="def" v-model="values" name="my-input" />

But when I refer to "default" in js it is undefined.

InputField.vue

<template>
<div >
    <input default="def" v-model="valuess" name="my-input" />
    
<input
      v-model="message"
      type="text">
      <h2 class="message">{{ message }}</h2>

</div>
</template>

<script>
    module.exports={
        name:'InputField',
        props:["default"],
        mounted(){

             console.log(this.default);
               this.valuess=this.default;
        },
        updated(){
            if(this.valuess===this.default){
                return this.$emit('dirty-field',false);
            }
            this.$emit('dirty-field',true);
        },
        data: function () {
            return {
                valuess: '',
                message:'heelo',
               
            }
        
    }
    }
</script>

index.html

<div id="app">
    <InputField default="My default text"></InputField>
   
    </div>

main.js

new Vue({

render: h => h(InputField),
}).$mount('#app');
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try to pass default props like this with :default:

<InputField :default="My default text"></InputField>
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!