gpt4 book ai didi

javascript - VueJs 使用 Axios 发布。错误变量未定义

转载 作者:行者123 更新时间:2023-12-03 01:19:21 25 4
gpt4 key购买 nike

我有这个代码

<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 吗?我对这些回应持开放态度。谢谢。

最佳答案

当你执行new Local()时,你需要向它传递参数。因此将创建的对象将具有定义的属性。

new Local('my address', 'my city', 'my contact')

关于javascript - VueJs 使用 Axios 发布。错误变量未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51834496/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com