Javascript 未从HTTP响应填充下拉列表
我不熟悉HTTP调用。我正在尝试将每个对象的(特定)属性填充到下拉列表中,但没有填充,我尝试了一些方法,例如for循环Javascript 未从HTTP响应填充下拉列表,javascript,vue.js,Javascript,Vue.js,我不熟悉HTTP调用。我正在尝试将每个对象的(特定)属性填充到下拉列表中,但没有填充,我尝试了一些方法,例如for循环 created(){ axios .get("https://jsonplaceholder.typicode.com/posts") .then(res => { let result = res.data for(i = 0; i <= result.length;i++){ this.todos = result[i
created(){
axios
.get("https://jsonplaceholder.typicode.com/posts")
.then(res => {
let result = res.data
for(i = 0; i <= result.length;i++){
this.todos = result[i];
}
})
}
这是我的全部。我错过了什么/做错了什么 这就是如何让它工作:
new Vue({
el: "#app",
data: {
user: {
todos: []
}
},
created(){
axios
.get("https://jsonplaceholder.typicode.com/posts")
.then(res => {
cosnt result = res.data
for(i = 0; i <= result.length;i++){
this.user.todos.push(result[i].title);
}
})
}
})
newvue({
el:“应用程序”,
数据:{
用户:{
待办事项:[]
}
},
创建(){
axios
.get(“https://jsonplaceholder.typicode.com/posts")
。然后(res=>{
cosnt结果=分辨率数据
对于(i=0;i这是如何使其工作的:
new Vue({
el: "#app",
data: {
user: {
todos: []
}
},
created(){
axios
.get("https://jsonplaceholder.typicode.com/posts")
.then(res => {
cosnt result = res.data
for(i = 0; i <= result.length;i++){
this.user.todos.push(result[i].title);
}
})
}
})
newvue({
el:“应用程序”,
数据:{
用户:{
待办事项:[]
}
},
创建(){
axios
.get(“https://jsonplaceholder.typicode.com/posts")
。然后(res=>{
cosnt结果=分辨率数据
对于(i=0;我很好。谢谢!是时候磨练我的JS技能了。还有一件事,数据是一个通用词吗?@Nofel,你是指Vue组件中的data
还是响应中的data
。很抱歉,我已经澄清了。data
来自响应这完全取决于你使用的API,它可以被称为任何东西。太好了。谢谢!是时候提高我的JS技能了。还有一件事,数据是一个通用词吗?@Nofel,你是指Vue组件中的数据
,还是响应中的数据
。抱歉,我已经澄清了。响应中的数据
完全取决于你使用的API,它可以被称为任何东西。
new Vue({
el: "#app",
data: {
user: {
todos: []
}
},
created(){
axios
.get("https://jsonplaceholder.typicode.com/posts")
.then(res => {
cosnt result = res.data
for(i = 0; i <= result.length;i++){
this.user.todos.push(result[i].title);
}
})
}
})