我有此代码
<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>
这个问题是这样的,可以从de class识别本地,这是错误的吗??? 最好是为此使用vue-resource? 我对回应持开放态度。谢谢。
答案 0 :(得分:1)
在执行新的Local()时,需要向其传递参数。 因此将要创建的对象将具有已定义的属性。
new Local('my address', 'my city', 'my contact')