vue3.0 + el-table

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

原文地址:https://www.cnblogs.com/moguzi12345/p/14658887.html