zoukankan      html  css  js  c++  java
  • vue part3.3 小案例ajax (axios) 及页面异步显示

     

    npm install axios --save 

    App.vue

    <template>
      <div>
        <div v-if="!repoName">loading</div>
        <div v-else>most start repo is <a :href="repoUrl">{{repoName}}</a></div>
      </div>
    </template>
    
    <script>
    import axios from 'axios'
    export default {
      data () {
        return {
          repoUrl: '',
          repoName: ''
        }
      },
      mounted () {
        const url = 'https://api.github.com/search/repositories?q=v&sort=stars'
        axios.get(url).then(response => {
          const result = response.data
          const mostRepo = result.items[0]
          this.repoUrl = mostRepo.html_url
          this.repoName = mostRepo.name
        }).catch(error => {
          alert('请求失败')
        })
      }
    
    }
    
    </script>
    
    <style>
    
    </style>
  • 相关阅读:
    Codeforces Round #534 (Div. 2) D. Game with modulo 交互题
    传球游戏 dp
    欧拉通路和欧拉回路
    HDU 1116
    HDU 4970
    HDU 4557
    HDU 4864
    HDU 1565
    HDU 3046
    HDU 4240
  • 原文地址:https://www.cnblogs.com/infaaf/p/9684047.html
Copyright © 2011-2022 走看看