axios獲取本地文件配置步驟


 

首先修改一下config文件夾下面的index.js文件里面的配置,如下:

 

然后 ,通過axios 請求配置的接口

<script>
  import axios from 'axios'
  export default {
    name: 'List',
    data(){
      return {
       list:[]
      }
    },
    mounted(){
     this.getData();//調用獲取數據函數
    },
    methods:{
      //定義頁面跳轉函數
      goDetail(e){
        const id=e.currentTarget.getAttribute("id");
        const name=e.currentTarget.innerText;
        this.$router.push({
          path:'detail',
          query:{id:id, name:name}
        })
      },
      //定義獲取數據函數
      getData(){
         axios.get('/api/index.json').then((res)=>{
              if(res.status==200){
                this.list=res.data.data.list;
              }
         }).catch((error)=>{
             console.log(error);
         })
      }
    }
  }
</script>

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM