I have two component
My first component like this :
<template>
<div>
...
<form-input id="name" name="name" v-model="name">Name</form-input>
...
<button type="submit" class="btn btn-primary" @click="submit">Submit</button>
</div>
</template>
<script>
export default {
data() {
return {
name: null
}
},
methods: {
submit() {
console.log('submit profile')
console.log(this.name)
}
}
}
</script>
On the first component, it will call form input component
The form input component like this :
<template>
<div class="form-group">
<label :for="id" class="col-sm-3 control-label"><slot></slot></label>
<div class="col-sm-9">
<input :type="type" :name="name" :id="id" class="form-control">
</div>
</div>
</template>
<script>
export default {
props: {
'id': String,
'name': String,
'type': {
type: String,
default() {
if(this.type == 'number')
return 'number'
return 'text'
}
},
}
}
</script>
I using pattern like that. So the form input component can be used in many components
But my problem here is : I can not retrieve the value when submitting button
I try like that, but the result of console.log(this.name) is null
I want when input data name and submit form, it will get the name
How can I solve this problem?