我正在调用天气API,以使用axios显示用户当前位置的天气数据。但是似乎有语法错误,但是我找不到我在哪里编码错误。请帮助我。
actions:{
currentCity({commit}) {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(position => {
axios
.get(`${this.url_base}weather?&lat=${position.coords.latitude}&lon=${position.coords.longitude}&units=metric&APPID=${this.api_key}`)
.then(res=>res.data)
.then(weather=>{
commit('currentCity',weather)
})
}}}
},
使用您的IDE。您显然没有按正确的顺序打开和关闭大括号和括号。如果您在大多数编辑器中单击了大括号/括号(甚至包括我以前用来查找的Google chrome JS控制台),它都会突出显示开头的一个,从而可以非常轻松快捷地找到语法错误...
actions: {
currentCity({commit})
{
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(position => {
axios
.get(`${this.url_base}weather?&lat=${position.coords.latitude}&lon=${position.coords.longitude}&units=metric&APPID=${this.api_key}`)
.then(res => res.data)
.then(weather => {
commit('currentCity', weather)
})
})
}
}
}