亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用axios獲取api數據時箭頭函數不應該返回賦值(Vue.js 2)

使用axios獲取api數據時箭頭函數不應該返回賦值(Vue.js 2)

慕森卡 2022-11-03 11:02:47
因此,我嘗試在我的 vue 應用程序中使用 Axios 從 URL 獲取數據,但它一直返回以下錯誤: Arrow function should not return assignment完整的錯誤輸出:error: Arrow function should not return assignment (no-return-assign) at src\components\navbar.vue:123:13:  121 |   created() {  122 |     axios.get('http://ip-api.com/json')> 123 |       .then((response) => (this.countryCode = response.countryCode));      |             ^  124 |   },  125 | };  126 | </script>1 error found.我的代碼:<script>import axios from 'axios';export default {  name: 'navbarr',  data() {    return {      countryCode: null,      country: '',      countries: [        { value: 'INT' },        { value: 'UK' },        { value: 'PT' },        { value: 'US' },        { value: 'FR' },        { value: 'DE' },        { value: 'IT' },        { value: 'ES' },        { value: 'IE' },      ],    };  },  created() {    axios.get('http://ip-api.com/json')      .then((response) => (this.countryCode = response.countryCode));  },};</script>我正在關注官方示例,但我無法理解這里有什么問題!
查看完整描述

1 回答

?
慕田峪7331174

TA貢獻1828條經驗 獲得超13個贊

這是違反ESLint 規則的。解決方案是使用大括號來指示您的箭頭函數實際上沒有返回值

.then((response) => {
  this.countryCode = response.countryCode}
  )

另一種選擇是except-parens在您的 ESLint 配置中設置該選項。


查看完整回答
反對 回復 2022-11-03
  • 1 回答
  • 0 關注
  • 332 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號