首先修改一下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>