VUEX:意外令牌,预期为“,”((轴))

问题描述 投票:0回答:1

我正在调用天气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)
                })            
    }}}
},
vue.js axios vuex
1个回答
0
投票

使用您的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)
                    })
            })
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.