<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Vue Day3【綜合案例1】小黑記賬清單

      1682071972085

      需求 & 思路分析

      1.基本渲染
      - 立刻發送請求獲取數據 created
      - 拿到數據,存到data的響應式數據中
      - 結合數據,進行渲染 v-for
      - 消費統計  —> 計算屬性
      
      2.添加功能
      - 收集表單數據 v-model,使用指令修飾符處理數據
      - 給添加按鈕注冊點擊事件,對輸入的內容做非空判斷,發送請求
      - 請求成功后,對文本框內容進行清空
      - 重新渲染列表
      
      3.刪除功能
      - 注冊點擊事件,獲取當前行的id
      - 根據id發送刪除請求
      - 需要重新渲染
      
      4.餅圖渲染
      - 初始化一個餅圖 echarts.init(dom)    mounted鉤子中渲染
      - 根據數據試試更新餅圖 echarts.setOptions({...})
      

      image

      <!DOCTYPE html>
      <html lang="en">
      
      <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <!-- CSS only -->
        <link rel="stylesheet"  />
        <style>
          .red {
            color: red !important;
          }
      
          .search {
            width: 300px;
            margin: 20px 0;
          }
      
          .my-form {
            display: flex;
            margin: 20px 0;
          }
      
          .my-form input {
            flex: 1;
            margin-right: 20px;
          }
      
          .table> :not(:first-child) {
            border-top: none;
          }
      
          .contain {
            display: flex;
            padding: 10px;
          }
      
          .list-box {
            flex: 1;
            padding: 0 30px;
          }
      
          .list-box a {
            text-decoration: none;
          }
      
          .echarts-box {
            width: 600px;
            height: 400px;
            padding: 30px;
            margin: 0 auto;
            border: 1px solid #ccc;
          }
      
          tfoot {
            font-weight: bold;
          }
      
          @media screen and (max-width: 1000px) {
            .contain {
              flex-wrap: wrap;
            }
      
            .list-box {
              width: 100%;
            }
      
            .echarts-box {
              margin-top: 30px;
            }
          }
        </style>
      </head>
      
      <body>
        <div id="app">
          <div class="contain">
            <!-- 左側列表 -->
            <div class="list-box">
      
              <!-- 添加資產 -->
              <form class="my-form">
                <input v-model.trim="name" type="text" class="form-control" placeholder="消費名稱" />
                <input v-model.number="price" type="text" class="form-control" placeholder="消費價格" />
                <button @click="add" type="button" class="btn btn-primary">添加賬單</button>
              </form>
      
              <table class="table table-hover">
                <thead>
                  <tr>
                    <th>編號</th>
                    <th>消費名稱</th>
                    <th>消費價格</th>
                    <th>操作</th>
                  </tr>
                </thead>
                <tbody>
                  <tr v-for="(item,index) in list" :key="item.id">
                    <td>{{ index + 1 }}</td>
                    <td>{{ item.name }}</td>
                    <td :class="{ red : item.price >= 500 }">{{ item.price.toFixed(2) }}</td>
                    <td><a @click="del(item.id)" href="javascript:;">刪除</a></td>
                  </tr>
                </tbody>
                <tfoot>
                  <tr>
                    <td colspan="4">消費總計: {{ totalPrice.toFixed(2) }}</td>
                  </tr>
                </tfoot>
              </table>
            </div>
      
            <!-- 右側圖表 -->
            <div class="echarts-box" id="main"></div>
          </div>
        </div>
        <script src="echarts.min.js"></script>
        <script src="vue.js"></script>
        <script src="axios.js"></script>
        <script>
          /**
           * 接口文檔地址:
           * http://localhost:3001
           * 
           * 功能需求:
           * 1. 基本渲染
           *    (1) 立刻發送請求獲取數據 created
           *    (2) 拿到數據,存到data的響應式數據中
           *    (3) 結合數據,進行渲染 v-for
           *    (4) 消費統計 => 計算屬性
           * 2. 添加功能
           *    (1) 收集表單數據 v-model
           *    (2) 給添加按鈕注冊點擊事件,發送添加請求
           *    (3) 需要重新渲染
           * 3. 刪除功能
           *    (1) 注冊點擊事件,傳參傳 id
           *    (2) 根據 id 發送刪除請求
           *    (3) 需要重新渲染
           * 4. 餅圖渲染
           *    (1) 初始化一個餅圖 echarts.init(dom)  mounted鉤子實現
           *    (2) 根據數據實時更新餅圖 echarts.setOption({ ... })
           */
          const app = new Vue({
            el: '#app',
            data: {
              list: [],
              name: '',
              price: ''
            },
            // 生命周期鉤子
            async created() {
              // const res = await axios('http://localhost:3001/bill', {
              //   params: {
              //     creator: '小黑'
              //   }
              // })
              // this.list = res.data
      
              this.getList()
            },
            // 餅圖在mounted鉤子中實現
            mounted() {
              // 基于準備好的dom,初始化echarts實例
              this.myChart = echarts.init(document.getElementById('main'))
              // 繪制圖表 (官網直接引入:ctrl cv)
              this.myChart.setOption({
                // 大標題
                title: {
                  text: '消費賬單列表',
                  subtext: 'Fake Data',
                  left: 'center'
                },
                // 提示框
                tooltip: {
                  trigger: 'item'
                },
                // 圖例
                legend: {
                  orient: 'vertical',
                  left: 'left'
                },
                // 數據項
                series: [
                  {
                    name: '消費賬單',
                    type: 'pie',
                    radius: '50%', // 半徑
                    data: [
                      // { value: 1048, name: 'Search Engine' },
                      // { value: 735, name: 'Direct' }
                    ],
                    emphasis: {
                      itemStyle: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                      }
                    }
                  }
                ]
              })
            },
            computed: {
              totalPrice() {
                return this.list.reduce((sum, item) => sum + item.price, 0)
              }
            },
            methods: {
              async getList() {
                const res = await axios('http://localhost:3001/bill', {
                  params: {
                    creator: '小黑'
                  }
                })
                this.list = res.data
      
                // 異步更新餅圖數據
                this.myChart.setOption({
                  // 數據項
                  series: [
                    {
                      data: this.list.map(item => ({ value: item.price, name: item.name })) // 返回的是對象,要添加括號表示是對象而不是代碼塊
                    }
                  ]
                })
              },
              async add() {
                if (!this.name === '' || !this.price === '' || typeof this.price !== 'number') {
                  alert('請輸入完整且正確的數據')
                  return
                }
                // 發送添加請求
                const res = await axios.post('http://localhost:3001/bill', {
                  id: (+new Date()).toString, // 自行補充的部分
                  creator: '小黑',
                  price: this.price,
                  name: this.name
                })
                // 重新渲染一次
                this.getList()
                this.name = ''
                this.price = ''
              },
              async del(id) {
                // console.log(id)
                const res = await axios.delete(`http://localhost:3001/bill/${id}`)
                this.getList()
              }
            }
          })
        </script>
      </body>
      
      </html>
      
      posted @ 2025-09-07 18:17  岑素月  閱讀(13)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 黄色亚洲一区二区在线观看| 国产片av在线观看国语| 粗壮挺进人妻水蜜桃成熟| 亚洲一区二区三区水蜜桃| 久久毛片少妇高潮| 亚洲男女羞羞无遮挡久久丫| 曝光无码有码视频专区| 欧洲尺码日本尺码专线美国又 | 亚洲国产色一区二区三区| 免费三级网站| 久久一区二区三区黄色片| 国产目拍亚洲精品二区| 台北市| 免费国产一级 片内射老| 免费一区二区无码东京热| 蜜臀av在线一区二区三区| 国产av无码专区亚洲av软件| 久久五月丁香合缴情网| 亚洲午夜理论无码电影| 国产人免费人成免费视频| 国产高清在线精品一本大道| 奇米影视7777狠狠狠狠色| 在线亚洲妇色中文色综合| 国产999久久高清免费观看| 国产乱码精品一区二区三区四川人| 色综合久久一区二区三区| 亚洲精品久久麻豆蜜桃| 亚洲精品国产老熟女久久| 日本高清在线观看WWW色| 一区二区中文字幕av| 精品亚洲国产成人| 福利视频一区二区在线| 丝袜美腿亚洲综合在线观看视频| 四虎影视永久在线精品| 九九热视频在线观看精品| 吉川爱美一区二区三区视频| 亚洲国产日韩伦中文字幕| 亚洲一二区在线视频播放| 人妻aⅴ无码一区二区三区| 国产又色又爽又黄的视频在线| 日韩精品一区二区三区蜜臀|