1、template:
<el-table :data="state.weather"> <el-table-column prop="id" label="日期" width="180"></el-table-column> <el-table-column prop="username" label="姓名" width="200"></el-table-column> <el-table-column prop="memberName" label="地址"></el-table-column> </el-table>
2、script:
import { defineComponent, onMounted, onUnmounted, ref, reactive } from 'vue' import axios from "axios"; export default defineComponent ({ name: 'Home', setup() {const state = reactive({}); // 定義數據
async function fetchData() { axios.post("/goods/goodall2").then((res)=>{ // 自定義mock數據 state.weather = res.data.data; // 賦值 console.log(state.weather); }).catch(function (error) {}); }
// 頁面加載時候執行 onMounted(() => { state.value = fetchData(); }); return { state, // table數組return }; } })
詳細的安裝 mock 看:https://www.cnblogs.com/moguzi12345/p/14524580.html