Reputation: 3
i m have this code
<script>
import axios from 'axios';
class Local {
constructor(adress, city, contact){
this.adress = adress;
this.city = city;
this.contact = contact;
}
}
export default {
data(){
return{
local: new Local()
}
},
methods:{
addLocal(){
axios.post("http://localhost:3000/api/local",{
local: new Local()
})
.then(res => console.log(JSON.res))
.catch(err => console.log(err));
local = new Local();
}
}
}
</script>
<form @submit.prevent="addLocal">
<div class="form-input">
<input type="text" v-model="local.adress" class="form-control" placeholder="Adress">
</div>
<div class="form-input">
<input type="text" v-model="local.city" class="form-control" placeholder="City">
</div>
<div class="form-input">
<input type="text" v-model='local.contact' class="form-control" placeholder="Contact">
</div>
<br>
<button class="btn btn-primary btn-block">Ready.</button>
<button class="btn btn-danger btn-block">Cancel</button>
</form>
This problem is some like this can recognize local from de class, is something wrong??? is best maybe using vue-resource for this? im open mind with the responses. Thanks.
Upvotes: 0
Views: 44
Reputation: 430
when you are executing new Local(), you need to pass parameter to it. so the object which will be created will have defined properties.
new Local('my address', 'my city', 'my contact')
Upvotes: 1