【问题标题】:VUEX: Unexpected token, expected "," (axios)VueX:意外的令牌,预期的“,”(axios)
【发布时间】:2020-09-19 14:47:01
【问题描述】:

我正在调用一个天气 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】:

    使用您的 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)
                        })
                })
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多