vue axios 4 实例化

vim demon03.vue

<template>
  <div class="home">
  </div>
</template>
<script>
import axios from 'axios'
export default {
  name: 'demon03',
  components: {},
  created() {
    //创建axios实例
    //axios实例:当后端地址有多个,并且超时时长不一样
    let instance01 = axios.create({
      baseURL: 'http://127.0.0.1:8080',
      timeout: 1000
    })
    let instance02 = axios.create({
      baseURL: 'http://127.0.0.1:8090',
      timeout: 1500
    })
    //使用axios实例
    instance01.get('/data.json').then(res=>{
      console.log(res)
    })
    instance02.get('city.json').then(res=>{
      console.log(res)
    })
  }
}
</script>

 

posted @ 2020-09-27 18:08  chenjianwen  阅读(527)  评论(0编辑  收藏  举报