欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于Vue2實現(xiàn)動態(tài)折扣表格

 更新時間:2024年01月14日 16:06:32   作者:上優(yōu)  
這篇文章主要為大家詳細介紹了如何基于Vue2實現(xiàn)動態(tài)折扣表格,文中的示例代碼講解詳細,具有一定的借鑒價值,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下

效果圖

實現(xiàn)代碼

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <!-- <link
      rel="stylesheet"
       rel="external nofollow" 
    />
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.13/vue.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/@unocss/runtime"></script>
    <script src="https://unpkg.com/element-ui/lib/index.js"></script> -->
    <link rel="stylesheet" href="./vue/element_ui.css" rel="external nofollow"  />
    <script src="./vue/vue.js"></script>
    <script src="./vue/unocss.js"></script>
    <script src="./vue/element_ui.js"></script>
    <style>
      * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
      }
    </style>
  </head>

  <body>
    <div id="app" class="h-100vh">
      <div class="h-full flex items-center justify-center">
        <div>
          <div class="flex items-center gap-10px">
            <div
              class="cursor-pointer bg-blue-500 text-white p-[2px_10px] w-max rounded-[4px] text-[12px]"
              @click="addRow"
            >
              + 行
            </div>
            <div
              class="cursor-pointer bg-blue-500 text-white p-[2px_10px] w-max rounded-[4px] text-[12px]"
              @click="addCol"
            >
              + 列
            </div>
          </div>

          <span> 打折: </span>
          <input
            type="text"
            class="bg-[unset] rounded-5px w-100px mt-[10px] outline-none border-solid border-[1px] border-blue-500 text-center"
            v-model="rate"
            @blur="handle()"
          />
          <table class="mt-[10px]">
            <tbody>
              <tr
                class="bg-violet-500/20 text-violet-500"
                v-for="(item, index) in list"
                :key="index"
              >
                <td class="text-center" v-for="(j, i) in item.child">
                  <input
                    type="text"
                    class="bg-[unset] outline-none h-full border-none text-center"
                    v-model="j.value"
                    @blur="handle(index,i)"
                  />
                </td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
    </div>
    <script>
      new Vue({
        el: '#app',
        data() {
          return {
            list: [
              {
                child: [
                  {
                    value: 800,
                  },
                  {
                    value: 200,
                  },
                ],
              },
            ],
            rate: 20,
          };
        },

        methods: {
          addRow() {
            const row = {
              child: [],
            };
            this.list[0].child.forEach((item) => {
              row.child.push({
                value: 0,
              });
            });
            this.list.push(row);
            this.handle();
          },
          addCol() {
            this.list.forEach((item) => {
              item.child.push({
                value: 0,
              });
            });
            this.handle();
          },

          handle(oneIndex, childIndex) {
            if (oneIndex == 0) {
              let newArr = this.list.filter((item, i) => i == 0);
              this.list
                .filter((item, index) => index > 0)
                .forEach((item, index) => {
                  item.child.forEach((j, i) => {
                    if (childIndex == i) {
                      j.value = (
                        newArr[0].child[i].value -
                        newArr[0].child[i].value *
                          (this.rate / 100) *
                          (index + 1)
                      ).toFixed(2);
                    }
                  });
                });
            }

            if (!oneIndex) {
              let newArr = this.list.filter((item, i) => i == 0);
              this.list
                .filter((item, index) => index > 0)
                .forEach((item, index) => {
                  item.child.forEach((j, i) => {
                    j.value = (
                      newArr[0].child[i].value -
                      newArr[0].child[i].value * (this.rate / 100) * (index + 1)
                    ).toFixed(2);
                  });
                });
            }
          },
        },
      });
    </script>
  </body>
</html>

以上就是基于Vue2實現(xiàn)動態(tài)折扣表格的詳細內(nèi)容,更多關(guān)于Vue2動態(tài)表格的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • 使用vite創(chuàng)建vue3項目的詳細圖文教程

    使用vite創(chuàng)建vue3項目的詳細圖文教程

    創(chuàng)建Vue3項目有兩種常見的方式,一種是想vue2版本一樣使用腳手架工具創(chuàng)建,創(chuàng)建vue3項目的腳手架必須是4版本以上的,另一種方法就是使用vite創(chuàng)建,這篇文章主要給大家介紹了關(guān)于如何使用vite創(chuàng)建vue3項目的相關(guān)資料,需要的朋友可以參考下
    2022-11-11
  • vue仿ios列表左劃刪除

    vue仿ios列表左劃刪除

    這篇文章主要為大家詳細介紹了vue仿ios列表左劃刪除,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-09-09
  • Vue項目中接口調(diào)用的詳細講解

    Vue項目中接口調(diào)用的詳細講解

    應(yīng)公司需求,接口需要對接vue,記錄一下碰到的問題,下面這篇文章主要給大家介紹了關(guān)于Vue項目中接口調(diào)用的詳細講解,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-07-07
  • vue 組件中添加樣式不生效的解決方法

    vue 組件中添加樣式不生效的解決方法

    這篇文章主要介紹了vue 組件中添加樣式不生效的解決方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-07-07
  • vue npm install 安裝某個指定的版本操作

    vue npm install 安裝某個指定的版本操作

    這篇文章主要介紹了vue npm install 安裝某個指定的版本操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-08-08
  • vuex頁面刷新導(dǎo)致數(shù)據(jù)丟失的解決方案

    vuex頁面刷新導(dǎo)致數(shù)據(jù)丟失的解決方案

    這篇文章主要介紹了vuex頁面刷新導(dǎo)致數(shù)據(jù)丟失的解決方案,幫助大家更好的使用vue框架,感興趣的朋友可以了解下
    2020-12-12
  • vue3項目typescript如何export引入(imported)的interface問題

    vue3項目typescript如何export引入(imported)的interface問題

    這篇文章主要介紹了vue3項目typescript如何export引入(imported)的interface問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-06-06
  • 基于Vue實現(xiàn)拖拽功能

    基于Vue實現(xiàn)拖拽功能

    這篇文章主要為大家詳細介紹了Vue實現(xiàn)拖拽功能,拖動方塊進行移動,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-04-04
  • Vue中的生命周期詳細解讀

    Vue中的生命周期詳細解讀

    這篇文章主要介紹了Vue中的生命周期詳細解讀,每個 Vue 組件實例在創(chuàng)建時都需要經(jīng)歷一系列的初始化步驟,比如設(shè)置好數(shù)據(jù)偵聽,編譯模板,掛載實例到 DOM,以及在數(shù)據(jù)改變時更新 DOM,需要的朋友可以參考下
    2023-08-08
  • vue2.0 獲取從http接口中獲取數(shù)據(jù),組件開發(fā),路由配置方式

    vue2.0 獲取從http接口中獲取數(shù)據(jù),組件開發(fā),路由配置方式

    今天小編就為大家分享一篇vue2.0 獲取從http接口中獲取數(shù)據(jù),組件開發(fā),路由配置方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-11-11

最新評論