【问题标题】:How to make API call using axios in Vue.js?如何在 Vue.js 中使用 axios 进行 API 调用?
【发布时间】:2019-12-30 09:50:26
【问题描述】:

我尝试在 vue.js 应用中使用 Axios 调用 API,API 调用成功但值不受影响。我想设置从 API 响应返回的值。

Sample URL

Vue.js 代码

new Vue({
  el: '#app',
  data () {
    return {
      info: null
    }
  },
  mounted () {
    axios
      .get('https://api.coindesk.com/v1/bpi/currentprice.json')
      .then(response => (this.info = response))
  }
})

HTML 代码

<script src="https://unpkg.com/vue"></script>

<div id="app">
  {{ info }}
</div>

【问题讨论】:

    标签: vue.js axios


    【解决方案1】:

    我想你错过了包含axios

    new Vue({
      el: '#app',
      data () {
        return {
          info: null
        }
      },
      mounted () {
        axios
          .get('https://api.coindesk.com/v1/bpi/currentprice.json')
          .then(response => (this.info = response))
      }
    })
    <script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.0/axios.js"></script>
    <script src="https://unpkg.com/vue"></script>
    
    <div id="app">
      {{ info }}
    </div>

    【讨论】:

      猜你喜欢
      • 2021-11-17
      • 1970-01-01
      • 2018-11-25
      • 2021-11-22
      • 2018-03-11
      • 2021-07-11
      • 1970-01-01
      • 2017-12-22
      • 2021-07-17
      相关资源
      最近更新 更多