最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue實現(xiàn)簡單的購物車小案例

 更新時間:2022年07月12日 17:23:37   作者:zhazhali_fenqi  
這篇文章主要為大家詳細(xì)介紹了vue實現(xiàn)簡單的購物車小案例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了vue實現(xiàn)簡單購物車的具體代碼,供大家參考,具體內(nèi)容如下

最近在寫vue的相關(guān)項目,所以找一些小例子練習(xí)一下,把一個js的購物車改成vue了

css部分是直接引入的插件

效果圖如下

<template>
<div class="head">
? ? <meta charset="UTF-8">
? ? <title>我的購物車-品優(yōu)購</title>
? ? <meta name="description" content="品優(yōu)購JD.COM-專業(yè)的綜合網(wǎng)上購物商城,銷售家電、數(shù)碼通訊、電腦、家居百貨、服裝服飾、母嬰、圖書、食品等數(shù)萬個品牌優(yōu)質(zhì)商品.便捷、誠信的服務(wù),為您提供愉悅的網(wǎng)上購物體驗!" />
? ? <meta name="Keywords" content="網(wǎng)上購物,網(wǎng)上商城,手機,筆記本,電腦,MP3,CD,VCD,DV,相機,數(shù)碼,配件,手表,存儲卡,品優(yōu)購" />
<!-- ? ?&lt;!&ndash; 引入facicon.ico網(wǎng)頁圖標(biāo) &ndash;&gt;-->
<!-- ? ?<link rel="shortcut icon" href="favicon.ico" rel="external nofollow"  type="image/x-icon" />-->
? ? <!-- 引入css 初始化的css 文件 -->
? ? <link rel="stylesheet" href="src/assets/carStyle/base.css" rel="external nofollow" >
? ? <!-- 引入公共樣式的css 文件 -->
? ? <link rel="stylesheet" href="src/assets/carStyle/common.css" rel="external nofollow" >
? ? <!-- 引入car css -->
? ? <link rel="stylesheet" href="src/assets/carStyle/car.css" rel="external nofollow" >
</div>
? <div class="body">
? ? <div class="car-header">
? ? ? <div class="w">
? ? ? ? <div class="car-logo">
? ? ? ? ? <img src="src/assets/images/logo.png" alt=""> <b>購物車</b>
? ? ? ? </div>
? ? ? </div>
? ? </div>
? ? <div class="c-container">
? ? ? <div class="w">
? ? ? ? <div class="cart-filter-bar">
? ? ? ? ? <em>全部商品</em>
? ? ? ? </div>
? ? ? ? <!-- 購物車主要核心區(qū)域 -->
? ? ? ? <div class="cart-warp">
? ? ? ? ? <!-- 頭部全選模塊 -->
? ? ? ? ? <div class="cart-thead">
? ? ? ? ? ? <div class="t-checkbox">
? ? ? ? ? ? ? <input type="checkbox" name="" id="" class="checkall"> 全選
? ? ? ? ? ? </div>
? ? ? ? ? ? <div class="t-goods">商品</div>
? ? ? ? ? ? <div class="t-price">單價</div>
? ? ? ? ? ? <div class="t-num">數(shù)量</div>
? ? ? ? ? ? <div class="t-sum">小計</div>
? ? ? ? ? ? <div class="t-action">操作</div>
? ? ? ? ? </div>
? ? ? ? ? <!-- 商品詳細(xì)模塊 -->
? ? ? ? ? <div class="cart-item-list" v-for="(good,index) in cartList">

? ? ? ? ? ? <div class="cart-item">
? ? ? ? ? ? ? <div class="p-checkbox">
? ? ? ? ? ? ? ? <input type="checkbox" v-model="good.isSelected" @click="oneSelected(index)">
? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? <div class="p-goods">
? ? ? ? ? ? ? ? <div class="p-img">
? ? ? ? ? ? ? ? ? <img v-bind:src=good.imgUrl alt="">
? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? ? <div class="p-msg">{{good.message}}</div>
? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? <div class="p-price">{{good.PriceItem}}</div>
? ? ? ? ? ? ? <div class="p-num">
? ? ? ? ? ? ? ? <div class="quantity-form">
? ? ? ? ? ? ? ? ? <el-button class="increment" @click="changeDe(index)">-</el-button>
? ? ? ? ? ? ? ? ? <input type="text" class="itxt" v-model=good.ItemNum placeholder="1">
? ? ? ? ? ? ? ? ? <el-button class="increment" @click="changeIn(index)">+</el-button>
? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? <div class="p-sum">{{good.PriceSum}}</div>
? ? ? ? ? ? ? <div class="p-action">
? ? ? ? ? ? ? ? <el-button type="danger" @click="DeleteItem(id)">刪除</el-button>
? ? ? ? ? ? ? </div>
? ? ? ? ? ? </div>
? ? ? ? ? </div>

? ? ? ? ? <!-- 結(jié)算模塊 -->
? ? ? ? ? <div class="cart-floatbar">
? ? ? ? ? ? <div class="select-all">
? ? ? ? ? ? ? <input type="checkbox" @click="allCheck" v-model="allSelected">全選
? ? ? ? ? ? </div>
? ? ? ? ? ? <div class="operation">
? ? ? ? ? ? ? <a class="remove-batch" @click="DeleteSelected"> 刪除選中的商品</a>
? ? ? ? ? ? ? <a class="clear-all" @click="DeleteAll">清理購物車</a>
? ? ? ? ? ? </div>
? ? ? ? ? ? <div class="toolbar-right">
? ? ? ? ? ? ? <div class="amount-sum">已經(jīng)選<em>{{NumSum}}</em>件商品</div>
? ? ? ? ? ? ? <div class="price-sum">總價: <em>{{totalPrice}}</em></div>
? ? ? ? ? ? ? <div class="btn-area">去結(jié)算</div>
? ? ? ? ? ? </div>
? ? ? ? ? </div>
? ? ? ? </div>
? ? ? </div>

? ? </div>
? </div>
</template>


<script>
import { defineComponent } from 'vue'
export default defineComponent({
? data(){
? ? return{
? ? ? allSelected:false,
? ? ? cartList:[
? ? ? ? {
? ? ? ? ? imgUrl:'src/assets/upload/p1.jpg',
? ? ? ? ? message:'【5本26.8元】經(jīng)典兒童文學(xué)彩圖青少版八十天環(huán)游地球中學(xué)生語文教學(xué)大綱',
? ? ? ? ? PriceItem: 12.6,
? ? ? ? ? PriceSum: 12.6,
? ? ? ? ? ItemNum: 1,
? ? ? ? ? isSelected:false
? ? ? ? },
? ? ? ? {
? ? ? ? ? imgUrl:'src/assets/upload/p2.jpg',
? ? ? ? ? message:'【2000張貼紙】貼紙書 3-6歲 貼畫兒童 貼畫書全套12冊 貼畫 貼紙兒童 汽',
? ? ? ? ? PriceItem: 24.8,
? ? ? ? ? PriceSum: 24.8,
? ? ? ? ? ItemNum: 1,
? ? ? ? ? isSelected:false
? ? ? ? },
? ? ? ? {
? ? ? ? ? imgUrl:'src/assets/upload/p3.jpg',
? ? ? ? ? message:'唐詩三百首+成語故事全2冊 一年級課外書 精裝注音兒童版 小學(xué)生二三年級課外閱讀書籍',
? ? ? ? ? PriceItem: 29.8,
? ? ? ? ? PriceSum: 29.8,
? ? ? ? ? ItemNum: 1,
? ? ? ? ? isSelected:false
? ? ? ? },
? ? ? ]
? ? }
? },
? methods:{
? ? ?changeIn(id){
? ? ? ?let n=this.cartList[id].ItemNum;
? ? ? ?// console.log(n);
? ? ? ?this.cartList[id].ItemNum++;
? ? ? ?this.cartList[id].PriceSum = this.cartList[id].ItemNum * this.cartList[id].PriceItem;
? ? ?},
? ? changeDe(id){
? ? ? ?if(this.cartList[id].ItemNum === 0)alert("該商品已經(jīng)清0!");
? ? ? ?else {
? ? ? ? ?this.cartList[id].ItemNum--;
? ? ? ? ?this.cartList[id].PriceSum = this.cartList[id].ItemNum * this.cartList[id].PriceItem;
? ? ? ?}
? ? },
? ? DeleteItem(id){
? ? ? ?// console.log(this.$parent);
? ? ? ?// console.log(this.$children);
? ? ? this.cartList.splice(id,1);
? ? },
? ? allCheck(){
? ? ? ?// console.log(this.allSelected);
? ? ?this.cartList.forEach((item)=>{
? ? ? ?// console.log(this.allSelected);
? ? ? ?// console.log(this.cartList);
? ? ? ?item.isSelected=!this.allSelected;
? ? ?})
? ? },
? ? DeleteSelected(){
? ? ? ?for(let i=0;i<this.cartList.length;i++){
? ? ? ? ?if(this.cartList[i].isSelected===true){
? ? ? ? ? ?this.cartList.splice(i,1);
? ? ? ? ?}
? ? ? ?}
? ? },
? ? DeleteAll(){
? ? ? this.cartList.splice(0,this.cartList.length);
? ? },
? ? oneSelected(id){
? ? ? ?if(this.cartList[id].isSelected===false)
? ? ? ? ?this.cartList[id].isSelected=true;
? ? ? ?else
? ? ? ? ?this.cartList[id].isSelected=false;

? ? ? let n=0;
? ? ? for(let i=0;i<this.cartList.length;i++){
? ? ? ? if(this.cartList[i].isSelected===true)
? ? ? ? ? n++;
? ? ? }
? ? ? if(n===this.cartList.length)this.allSelected=true;
? ? ? else this.allSelected=false;
? ? }
? },
? computed:{
? ? NumSum() {
? ? ? let num=0;
? ? ? this.cartList.forEach((item)=>{
? ? ? ? if(item.isSelected===true)
? ? ? ? num++;
? ? ? })
? ? ? return num;
? ? },
? ? totalPrice() {
? ? ? let totalp=0;
? ? ? this.cartList.forEach((item)=>{
? ? ? ? if(item.isSelected===true)
? ? ? ? ? totalp += item.PriceSum;
? ? ? })
? ? ? return totalp;
? ? },
? }
})

</script>
<style lang="scss" scoped>

</style>

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

相關(guān)文章

  • Vue.js+express利用切片實現(xiàn)大文件斷點續(xù)傳

    Vue.js+express利用切片實現(xiàn)大文件斷點續(xù)傳

    斷點續(xù)傳就是要從文件已經(jīng)下載的地方開始繼續(xù)下載,本文主要介紹了Vue.js+express利用切片實現(xiàn)大文件斷點續(xù)傳,具有一定的參考價值,感興趣的可以了解下
    2023-05-05
  • Vuejs第十三篇之組件——雜項

    Vuejs第十三篇之組件——雜項

    組件(Component)是 Vue.js 最強大的功能之一。本文重點給大家介紹vuejs組件相關(guān)知識,非常不錯,具有參考借鑒價值,感興趣的朋友一起看看吧
    2016-09-09
  • 使用mockjs如何生成隨機數(shù)據(jù)

    使用mockjs如何生成隨機數(shù)據(jù)

    Mockjs是一個用于生成隨機數(shù)據(jù)和攔截Ajax請求的庫,可以與Vue和Axios結(jié)合使用,提高前端開發(fā)效率,通過在項目中引入Mock.js文件,可以模擬后端API,攔截Ajax請求并返回自定義響應(yīng),這種方法適用于在后端尚未開發(fā)完成時的前端開發(fā)測試
    2024-10-10
  • vue中如何創(chuàng)建多個ueditor實例教程

    vue中如何創(chuàng)建多個ueditor實例教程

    這篇文章主要給大家介紹了關(guān)于vue中如何創(chuàng)建多個ueditor的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-11-11
  • 示例vue 的keep-alive緩存功能的實現(xiàn)

    示例vue 的keep-alive緩存功能的實現(xiàn)

    這篇文章主要介紹了示例vue 的keep-alive緩存功能的實現(xiàn),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-12-12
  • vue點擊Dashboard不同內(nèi)容 跳轉(zhuǎn)到同一表格的實例

    vue點擊Dashboard不同內(nèi)容 跳轉(zhuǎn)到同一表格的實例

    這篇文章主要介紹了vue點擊Dashboard不同內(nèi)容 跳轉(zhuǎn)到同一表格的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-11-11
  • vue報錯之exports is not defined問題的解決

    vue報錯之exports is not defined問題的解決

    這篇文章主要介紹了vue報錯之exports is not defined問題的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-07-07
  • vue2.* element tabs tab-pane 動態(tài)加載組件操作

    vue2.* element tabs tab-pane 動態(tài)加載組件操作

    這篇文章主要介紹了vue2.* element tabs tab-pane 動態(tài)加載組件操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-07-07
  • vue項目中掃碼支付的實現(xiàn)示例(附demo)

    vue項目中掃碼支付的實現(xiàn)示例(附demo)

    本文主要介紹了vue項目中掃碼支付的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • Vue3 組件間通信之mitt實現(xiàn)任意組件間通信的步驟

    Vue3 組件間通信之mitt實現(xiàn)任意組件間通信的步驟

    mitt 主要有4個API:emit(觸發(fā)某個事件)、on(綁定事件)、off(解綁某個事件)、all(獲取所有綁定的事件),這篇文章主要介紹了Vue3 組件間通信之mitt實現(xiàn)任意組件間通信,需要的朋友可以參考下
    2024-05-05

最新評論

定南县| 台南市| 崇阳县| 漯河市| 武城县| 英吉沙县| 襄樊市| 咸丰县| 广宗县| 黑龙江省| 镇雄县| 朝阳市| 舞阳县| 忻州市| 韩城市| 淮阳县| 淮滨县| 绥中县| 司法| 饶河县| 报价| 毕节市| 鹤峰县| 繁昌县| 高安市| 铜陵市| 凤山市| 焦作市| 兴城市| 永福县| 克什克腾旗| 溆浦县| 徐水县| 咸宁市| 民丰县| 始兴县| 根河市| 安溪县| 嘉禾县| 荔浦县| 喀喇沁旗|