<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>