vue - axios

npm install axios

只需要导入axios就可以使用了,尽量在app中导入,因为这样其它组件就可以直接使用

  import axios from 'axios'

使用:

<script>
import axios from "axios";

export default {
  name: 'SearchUser',
  data() {
    return {
      userName: ''
    }
  },
  methods: {
    searchUser() {
      axios.get( `https://api.github.com/search/users?q=${this.userName}`).then(
          response => {
            this.$globalEventBus.$emit("setUsers",response.data)
          },
          error => {
            console.log(error.message)
          }
      )
    }
  }
}
</script>

 

官网

posted on 2022-05-21 16:38  每天积极向上  阅读(20)  评论(0编辑  收藏  举报

导航