家庭记账本6

完成主页

 

<template>
  <div class="home">
    <el-button type="primary" @click="$router.push('/noteAdd')"
      >新增信息</el-button
    >
    <el-table :data="items" style="width: 100%">
      <el-table-column prop="money" label="账目"> </el-table-column>
      <el-table-column prop="msg" label="备注"> </el-table-column>
      <el-table-column prop="date" label="日期"> </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <div>
            <el-button
              type="text"
              @click="$router.push(`/noteUpdate?id=${scope.row.id}`)"
              >编辑</el-button
            >
            <el-button type="text" @click="delById(scope.row.id)"
              >删除</el-button
            >
          </div>
        </template>
      </el-table-column>
    </el-table>
   
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "HomeView",
  data() {
    return {
      items: [],
    };
  },

  methods: {
    async getData() {
      var res = await axios.get("http://localhost:9090/note");
      this.items = res.data.data;
      console.log(res.data.data);
      console.log(this.items.map(item => item.msg));
      
    },
    async delById(id) {
      await axios.delete("http://localhost:9090/note/" + id);
      this.getData();
    },
    
  },
  created() {
    this.getData();
  },
 
};
</script>

 

posted on 2024-02-23 22:10  Daniel350  阅读(11)  评论(0)    收藏  举报