首页 > 移动平台 > 详细

vue part3.3 ajax (axios) 及页面异步显示

时间:2018-09-21 00:31:20      阅读:213      评论:0      收藏:0      [点我收藏+]

技术分享图片

技术分享图片

 

 技术分享图片

 

 

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>

 

vue part3.3 ajax (axios) 及页面异步显示

原文:https://www.cnblogs.com/infaaf/p/9684047.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!