vue+ElementUI實(shí)現(xiàn)訂單頁動(dòng)態(tài)添加產(chǎn)品數(shù)據(jù)效果實(shí)例代碼
這兩天學(xué)習(xí)了ElementUI基于vue2.0開發(fā)學(xué)習(xí),這個(gè)知識(shí)點(diǎn)挺多的,而且很重要,所以,今天添加一點(diǎn)小筆記。
使用vue2.0(ElementUI基于vue2.0)+ElementUI(餓了么出品)實(shí)現(xiàn)的在訂單頁面動(dòng)態(tài)添加產(chǎn)品的效果,并自動(dòng)計(jì)算總價(jià)。代碼直接保存為html文檔,使用瀏覽器打開即可查看效果。
效果圖:
<html> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" /> <!-- 引入element樣式 --> <link rel="stylesheet" rel="external nofollow" > <title>訂單頁面</title> </head> <body> <div id="orderTest"> <el-dialog title="產(chǎn)品庫(kù)" v-model="dialogTableVisible"> <el-table :data="list"> <el-table-column property="name" label="產(chǎn)品名稱" width="150"></el-table-column> <el-table-column property="price" label="單價(jià)" width="200"></el-table-column> <el-table-column :context="_self" inline-template label="操作"> <div> <el-button size="small" @click="choise(row)"> 選擇 </el-button> </div> </el-table-column> </el-table> </el-dialog> <el-button type="info" icon="view" @click="dialogTableVisible = true">選擇產(chǎn)品</el-button> <span v-show="checkedNames.length>0" style="font-family: Microsoft YaHei">總價(jià):{{sumPrice}}元</span> <el-table :data="checkedNames" v-show="checkedNames.length>0"> <el-table-column property="name" label="產(chǎn)品名稱" width="150"></el-table-column> <el-table-column property="price" label="單價(jià)" width="200"></el-table-column> <el-table-column inline-template label="數(shù)量" width="200"> <el-input-number v-model="row.num" :min="1" :max="10"></el-input-number> </el-table-column> <el-table-column :context="_self" inline-template label="操作"> <i class="el-icon-circle-cross" @click="del(row)" title="刪除"></i> </el-table-column> </el-table> </div> </body> <!-- 引入vue --> <script src="https://unpkg.com/vue/dist/vue.js"></script> <!-- 引入element JS --> <script src="https://unpkg.com/element-ui/lib/index.js"></script> <script src="http://cdn.bootcss.com/jquery/3.1.1/jquery.js"></script> <script type="text/javascript"> var order = new Vue({ el: '#orderTest', data: { dialogTableVisible:false, checkedNames: [], list:[ {name:"iphone7",price:5688,num:1}, {name:"榮耀8",price:2299,num:1}, {name:"Lumia830",price:1299,num:1} ] }, computed:{ sumPrice:function(){ var sum = 0 ; for(var i=0;i< this.checkedNames.length;i++){ sum+=this.checkedNames[i].price*this.checkedNames[i].num; } return sum; } }, methods:{ choise:function(p){ order.checkedNames.push(p); }, del:function(p){ order.checkedNames.splice($.inArray(p, order.checkedNames), 1); }, } }); </script> </html>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Vue+ElementUI實(shí)現(xiàn)表單動(dòng)態(tài)渲染、可視化配置的方法
- 基于Vue+elementUI實(shí)現(xiàn)動(dòng)態(tài)表單的校驗(yàn)功能(根據(jù)條件動(dòng)態(tài)切換校驗(yàn)格式)
- VUE2.0+ElementUI2.0表格el-table循環(huán)動(dòng)態(tài)列渲染的寫法詳解
- 詳解Vue Elementui中的Tag與頁面其它元素相互交互的兩三事
- elementUI Vue 單個(gè)按鈕顯示和隱藏的變換功能(兩種方法)
- vue使用ElementUI時(shí)導(dǎo)航欄默認(rèn)展開功能的實(shí)現(xiàn)
- Vue ElementUI之Form表單驗(yàn)證遇到的問題
- Spring boot + mybatis + Vue.js + ElementUI 實(shí)現(xiàn)數(shù)據(jù)的增刪改查實(shí)例代碼(二)
- 使用vue.js2.0 + ElementUI開發(fā)后臺(tái)管理系統(tǒng)詳細(xì)教程(一)
- 詳解VUE Element-UI多級(jí)菜單動(dòng)態(tài)渲染的組件
相關(guān)文章
vue3 ts組合式API異常onMounted is called when&
這篇文章主要為大家介紹了vue3 ts組合式API異常onMounted is called when there is no active component問題解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-05-05Vue Router動(dòng)態(tài)路由使用方法總結(jié)
這篇文章主要介紹了Vue Router動(dòng)態(tài)路由使用方法總結(jié),需要的朋友可以參考下2023-10-10淺談VUE單頁應(yīng)用首屏加載速度優(yōu)化方案
這篇文章主要介紹了淺談VUE單頁應(yīng)用首屏加載速度優(yōu)化方案,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-08-08使用vue深度選擇器修改ElementUI組件內(nèi)樣式的示例代碼
在帶有scoped屬性的style中書寫樣式時(shí),無法作用影響到子組件中的樣式,此時(shí)我們會(huì)使用到deep深度選擇器,來解決此問題,我們?cè)谑褂胠ess預(yù)處理器,能正常使用,但是在scss預(yù)處理器中會(huì)報(bào)錯(cuò),下面通過本文介紹vue深度選擇器修改ElementUI組件內(nèi)樣式,需要的朋友可以參考下2022-12-12