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

vue實(shí)現(xiàn)可改變購(gòu)物數(shù)量的購(gòu)物車

 更新時(shí)間:2021年07月19日 14:11:04   作者:yfy538  
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)可改變購(gòu)物數(shù)量的購(gòu)物車,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了vue實(shí)現(xiàn)改變購(gòu)物數(shù)量的購(gòu)物車,供大家參考,具體內(nèi)容如下

效果圖:

知識(shí)點(diǎn):

1.computed 計(jì)算屬性
2.filters 過濾器

實(shí)現(xiàn)代碼:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<style>
    table {
        border-collapse: collapse;
        border-spacing: 0;
        border: 1px solid #ccc;
    }
    
    td,
    th {
        padding: 8px 16px;
        border: 1px solid #ccc;
        text-align: left;
    }
    
    th {
        background-color: #f7f7f7;
        color: #5c6b77;
    }
</style>

<body>
    <div id="box">
        <div v-if="books.length">
            <table>
                <thead>
                    <tr>
                        <th></th>
                        <th>書籍名字</th>
                        <th>出版日期</th>
                        <th>價(jià)格</th>
                        <th>購(gòu)買數(shù)量</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for="(item,index) in books">
                        <td>{{item.id}}</td>
                        <td>{{item.name}}</td>
                        <td>{{item.date}}</td>
                        <td>{{item.price | toprice}}</td>
                        <td>
                            <button @click='down(index)' :disabled="item.aunt<=1">-</button> {{item.aunt}}
                            <button @click='add(index)'>+</button>
                        </td>
                        <td>
                            <button @click="remove(index)">移除</button>
                        </td>
                    </tr>
                </tbody>
            </table>
            <h2>總價(jià):{{getallprice | toprice}}</h2>
        </div>
        <h2 v-else>您沒有購(gòu)物信息</h2>
    </div>
    <script>
        const vm = new Vue({
            el: "#box",
            data: {
                books: [{
                    id: 1,
                    name: "《vue.js實(shí)戰(zhàn)》",
                    date: "2010.2.4",
                    price: 82.00,
                    aunt: 1
                }, {
                    id: 2,
                    name: "《javascript實(shí)戰(zhàn)》",
                    date: "2010.2.4",
                    price: 108.00,
                    aunt: 1
                }, {
                    id: 3,
                    name: "《html+css實(shí)戰(zhàn)》",
                    date: "2010.2.4",
                    price: 42.50,
                    aunt: 1
                }, {
                    id: 4,
                    name: "《axios實(shí)戰(zhàn)》",
                    date: "2010.2.4",
                    price: 82.00,
                    aunt: 1
                }, {
                    id: 5,
                    name: "《jquery實(shí)戰(zhàn)》",
                    date: "2010.2.4",
                    price: 65.20,
                    aunt: 1
                }, ]
            },
            methods: {
                add(index) {
                    this.books[index].aunt++;
                },
                down(index) {
                    this.books[index].aunt--;
                },
                remove(index) {
                    this.books.splice(index, 1)
                },

            },
            computed: {
                getallprice() {
                    let all = 0;
                    for (let i = 0; i < this.books.length; i++) {
                        all += this.books[i].price * this.books[i].aunt
                    }
                    return all
                }
            },
            filters: {
                toprice(price) {
                    return '¥' + price.toFixed(2)
                },

            }
        })
    </script>
</body>

</html>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 關(guān)于echarts?清空上一次加載的數(shù)據(jù)問題

    關(guān)于echarts?清空上一次加載的數(shù)據(jù)問題

    這篇文章主要介紹了關(guān)于echarts?清空上一次加載的數(shù)據(jù)問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-10-10
  • 淺談Vue SSR中的Bundle的具有使用

    淺談Vue SSR中的Bundle的具有使用

    這篇文章主要介紹了淺談Vue SSR中的Bundle的具有使用,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-11-11
  • element?ui富文本編輯器的使用效果與步驟(quill-editor)

    element?ui富文本編輯器的使用效果與步驟(quill-editor)

    富文本編輯器在任何項(xiàng)目中都會(huì)用到,在Element中我們推薦vue-quill-editor組件,下面這篇文章主要給大家介紹了關(guān)于element?ui富文本編輯器的使用效果與步驟(quill-editor)的相關(guān)資料,需要的朋友可以參考下
    2022-10-10
  • vue中如何引入html靜態(tài)頁(yè)面

    vue中如何引入html靜態(tài)頁(yè)面

    這篇文章主要介紹了vue中如何引入html靜態(tài)頁(yè)面,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-01-01
  • vuex實(shí)現(xiàn)歷史記錄的示例代碼

    vuex實(shí)現(xiàn)歷史記錄的示例代碼

    這篇文章主要介紹了vuex實(shí)現(xiàn)歷史記錄的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-05-05
  • vue阻止頁(yè)面回退的實(shí)現(xiàn)方法(瀏覽器適用)

    vue阻止頁(yè)面回退的實(shí)現(xiàn)方法(瀏覽器適用)

    這篇文章主要介紹了vue阻止頁(yè)面回退的實(shí)現(xiàn)方法(瀏覽器適用),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-05-05
  • Vue3+antDesignVue實(shí)現(xiàn)表單校驗(yàn)的方法

    Vue3+antDesignVue實(shí)現(xiàn)表單校驗(yàn)的方法

    這篇文章主要為大家詳細(xì)介紹了基于Vue3和antDesignVue實(shí)現(xiàn)表單校驗(yàn)的方法,文中的示例代碼講解詳細(xì),具有一定的參考價(jià)值,需要的小伙伴可以了解下
    2024-01-01
  • vue通過子組件修改父組件prop的多種實(shí)現(xiàn)方式

    vue通過子組件修改父組件prop的多種實(shí)現(xiàn)方式

    這篇文章主要介紹了vue通過子組件修改父組件prop的幾種實(shí)現(xiàn)方式,比較常用的方式是通過Prop單向傳遞的規(guī)則,需要的朋友可以參考下
    2021-09-09
  • Vue使用axios進(jìn)行g(shù)et請(qǐng)求拼接參數(shù)的2種方式詳解

    Vue使用axios進(jìn)行g(shù)et請(qǐng)求拼接參數(shù)的2種方式詳解

    axios中post請(qǐng)求都是要求攜帶參數(shù)進(jìn)行請(qǐng)求,這篇文章主要給大家介紹了關(guān)于Vue使用axios進(jìn)行g(shù)et請(qǐng)求拼接參數(shù)的2種方式,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-01-01
  • vue項(xiàng)目中使用TDesign的方法

    vue項(xiàng)目中使用TDesign的方法

    tdesign-vue是TDesign 適配桌面端的組件庫(kù),適合在 vue 2 技術(shù)棧項(xiàng)目中使用,這篇文章主要介紹了vue項(xiàng)目中使用TDesign?,需要的朋友可以參考下
    2023-04-04

最新評(píng)論