Vue.js 从API密钥获取温度数据

Vue.js 从API密钥获取温度数据,vue.js,vuejs2,axios,Vue.js,Vuejs2,Axios,我正在尝试从api获取温度数据。我不能让它工作。我做错了什么?我需要在显示结果的div中使用v-for或其他东西吗 newvue({ el:“应用程序”, 数据(){ 返回{ api_键:“ADF173DFDCD1A6AEA78BA1265119177”, 基本url:'https://api.openweathermap.org/data/2.5/', 天气:{}, 查询:“” } }, 方法:{ 格拉布威瑟{ axios.get(`api.openweathermap.org/data/2

我正在尝试从api获取温度数据。我不能让它工作。我做错了什么?我需要在显示结果的div中使用v-for或其他东西吗

newvue({
el:“应用程序”,
数据(){
返回{
api_键:“ADF173DFDCD1A6AEA78BA1265119177”,
基本url:'https://api.openweathermap.org/data/2.5/',
天气:{},
查询:“”
}
},
方法:{
格拉布威瑟{
axios.get(`api.openweathermap.org/data/2.5/weather?id=${this.query}&appid=${this.api_key}`)
。然后(响应=>{
this.weather=response.data;
})
}
}
})

温度:
{{weather.name}
{{weather.temp}}
抓住

我调整了以下各项,然后似乎工作正常

  • 将完整URL馈送到axios.get中,如
    ${this.base\u URL}天气?

  • 不确定查询参数的
    parameter=id
    是什么意思,我粗略地阅读了api.openweathermap.com中的用户指南,然后将其更改为
    q=${this.query}
    (它将按一个城市名称查询天气信息)

  • newvue({
    el:“应用程序”,
    数据(){
    返回{
    api_键:“ADF173DFDCD1A6AEA78BA1265119177”,
    基本url:'https://api.openweathermap.org/data/2.5/',
    天气:{},
    问题:“圣何塞”
    }
    },
    方法:{
    格拉布威瑟{
    获取(`this.base\u url}天气?q=${this.query}&appid=${this.api\u key}`)
    。然后(响应=>{
    this.weather=response.data;
    })
    }
    }
    })
    
    温度:
    {{weather.name}

    {{weather.main} 抓住
    我调整了以下各项,然后似乎工作正常

  • 将完整URL馈送到axios.get中,如
    ${this.base\u URL}天气?

  • 不确定查询参数的
    parameter=id
    是什么意思,我粗略地阅读了api.openweathermap.com中的用户指南,然后将其更改为
    q=${this.query}
    (它将按一个城市名称查询天气信息)

  • newvue({
    el:“应用程序”,
    数据(){
    返回{
    api_键:“ADF173DFDCD1A6AEA78BA1265119177”,
    基本url:'https://api.openweathermap.org/data/2.5/',
    天气:{},
    问题:“圣何塞”
    }
    },
    方法:{
    格拉布威瑟{
    获取(`this.base\u url}天气?q=${this.query}&appid=${this.api\u key}`)
    。然后(响应=>{
    this.weather=response.data;
    })
    }
    }
    })
    
    温度:
    {{weather.name}

    {{weather.main} 抓住
    您不应该在帖子中包含API键。您不应该在帖子中包含API键。