当前位置: 首页 > news >正文

网站模板安装步骤搞钱的路子网站

网站模板安装步骤,搞钱的路子网站,深圳公布最新出行政策,网站公司 模板让我们利用所学知识来开发一个简单的购物车 #xff08;记得暴露属性和方法#xff01;#xff01;#xff01;#xff09; 首先来看一下最基本的一个html框架 !DOCTYPE html html langen headmeta charsetUTF-8记得暴露属性和方法 首先来看一下最基本的一个html框架 !DOCTYPE html html langen headmeta charsetUTF-8meta nameviewport contentwidthdevice-width, initial-scale1.0title实战小项目:购物车/titlestylebody {font-family: Arial, sans-serif;}.cart-item {width: 50%;margin-bottom: 15px;padding: 10px;border: 2px solid gray;border-radius: 10px;background-color: #ddd;}.buttons {margin-top: 5px;}.buttons button {padding: 5px 10px;margin-right: 5px;font-size: 16px;cursor: pointer;border: none;border-radius: 3px;background-color: pink;}.buttons input {width: 25px;}.buttons button:hover {background-color: yellow;}.quantity {font-size: 18px;font-weight: bold;margin-left: 10px;}h1, h2 {color: #333;}/style /head bodydiv idapph1实战小项目:购物车/h1!-- 提示可以使用v-for指令假设有n个品类则生成n个商品项--div classcart-itemdiv classbuttonsspan苹果 nbsp;nbsp;/spanbutton-/buttonspan classquantity1nbsp;nbsp;/spanbutton/buttonp请输入价格input typetext/ 元/斤 br 单价1 元/斤/p/div/div!-- 提示可以用计算属性或数据变动侦听器跟踪商品数和单价的变化进而求出总数和总价--h3商品总数: ins 1 /ins 件/h3h3商品总价: ins 1 /ins 元/h3/divscript typemoduleimport { createApp, reactive, computed } from ./vue.esm-browser.jscreateApp({setup() {// 1.定义属性存储商品的响应式数组 // 2.定义方法增加商品数// 3.定义方法减少商品数// 4.定义方法计算商品总数// 5.定义方法计算商品总价// 6.暴露属性和方法}}).mount(#app);/script /body /html 效果如下 目前是一个静态的一个网页 首先定义属性存储商品的响应式数组使用v-for遍历 div classcart-item v-for(item,index) in cartItemsconst cartItems reactive([{ name: 苹果, quantity: 1, unit_price: 1 },{ name: 香蕉, quantity: 1, unit_price: 1 },{ name: 菠萝, quantity: 1, unit_price: 1 },]); 我们可以发现我们已经做出了三个链接但是名字都是苹果这个时候我们添加一个插值即可 span{{item.name}}nbsp;nbsp;/span 那么我们如何控制商品的增加和减少呢 我们只需要定义一个函数 并且使用v-on的方法绑定即可事件触发为点击 注意在做减少按钮时我们要通过if判断限制一下商品数否则会出现负数 button v-on:click pre(index)-/buttonspan classquantity{{cartItems[index].quantity}} nbsp;nbsp;/spanbutton v-on:click next(index)/button// 2.定义方法增加商品数const next (index) {cartItems[index].quantity ;} // 3.定义方法减少商品数const pre (index) {if ( cartItems[index].quantity1) {cartItems[index].quantity --;}} 接着我们要计算商品的总数那么该如何计算呢 可以用计算属性或数据变动侦听器跟踪商品数和单价的变化进而求出总数和总价 h3商品总数: ins {{totalItem()}} /ins 件/h3// 4.定义方法计算商品总数const totalItem () {let total_items 0 ;for(const item of cartItems){total_items item.quantity;}return total_items} 计算完总数我们就该来计算总价了同理可得使用computer计算属性定义一个变量在函数里面写一个for遍历即可输入框里面属于写一个双向绑定v-model从而实现单价变化总价随着变化 input typetext v-modelcartItems[index].unit_price 元/斤 br h3商品总价: ins {{totalprice}} /ins 元/h3// 5.定义方法计算商品总价const totalprice computed((){let total_price 0; for(const money of cartItems){ total_price money.unit_price*money.quantity; }return total_price }) 这样我们一个简单的购物车便开发成功啦 完整代码如下 !DOCTYPE html html langen headmeta charsetUTF-8meta nameviewport contentwidthdevice-width, initial-scale1.0title实战小项目:购物车/titlestylebody {font-family: Arial, sans-serif;}.cart-item {width: 50%;margin-bottom: 15px;padding: 10px;border: 2px solid gray;border-radius: 10px;background-color: #ddd;}.buttons {margin-top: 5px;}.buttons button {padding: 5px 10px;margin-right: 5px;font-size: 16px;cursor: pointer;border: none;border-radius: 3px;background-color: pink;}.buttons input {width: 25px;}.buttons button:hover {background-color: yellow;}.quantity {font-size: 18px;font-weight: bold;margin-left: 10px;}h1, h2 {color: #333;}/style /head bodydiv idapph1实战小项目:购物车/h1!-- 提示可以使用v-for指令假设有n个品类则生成n个商品项--div classcart-item v-for(item,index) in cartItemsdiv classbuttonsspan{{item.name}}nbsp;nbsp;/spanbutton v-on:click pre(index)-/buttonspan classquantity{{cartItems[index].quantity}} nbsp;nbsp;/spanbutton v-on:click next(index)/buttonp请输入价格input typetext v-modelcartItems[index].unit_price 元/斤 br 单价1 元/斤/p/div/div!-- 提示可以用计算属性或数据变动侦听器跟踪商品数和单价的变化进而求出总数和总价--h3商品总数: ins {{totalItem()}} /ins 件/h3h3商品总价: ins {{totalprice}}/ins 元/h3/divscript typemoduleimport { createApp, reactive, computed } from ./vue.esm-browser.jscreateApp({setup() {// 1.定义属性存储商品的响应式数组 const cartItems reactive([{ name: 苹果, quantity: 1, unit_price: 1 },{ name: 香蕉, quantity: 1, unit_price: 1 },{ name: 菠萝, quantity: 1, unit_price: 1 },]);// 2.定义方法增加商品数const next (index) {cartItems[index].quantity ;} // 3.定义方法减少商品数const pre (index) {if ( cartItems[index].quantity1) {cartItems[index].quantity --;}}// 4.定义方法计算商品总数const totalItem () {let total_items 0 ;for(const item of cartItems){total_items item.quantity;}return total_items}// 5.定义方法计算商品总价const totalprice computed((){let total_price 0; for(const money of cartItems){ total_price money.unit_price*money.quantity; }return total_price })// 6.暴露属性和方法return {cartItems,pre,next,totalItem,totalprice,};},}).mount(#app);/script /body /html
http://www.hkea.cn/news/14322644/

相关文章:

  • 南京做网站公司地点seo技术培训泰州
  • 可以跟关键词密度过高的网站交换友情链接吗网站结构怎么优化
  • 快捷的赣州网站建设扬州网站建设制作
  • 企业网站建设怎么做嘉兴网站推广平台
  • 云和建设局网站h5交互设计
  • 安徽网站建设方案开发wordpress顶部广告
  • 北京网站建设上石榴汇在线浏览器
  • 网站服务器和空间的区别宁波免费自助建站模板
  • 大连网站网站搭建制作iis如何做同时运行两个网站80端口
  • 网页设计与网站建设程序作业淘宝客网站免费建站
  • 网站域名账号如何用ps做网站首页图片
  • 壁纸公司网站源码fqapps com网站怎么做
  • 医疗在线网站建设html5网站上线模版
  • 移动微网站建设深圳建筑工地招工招聘信息
  • 网站换稳定服务器零基础网站建设教学在哪里
  • wordpress做分类信息网站请别人做网站的缺点
  • 庄河做网站上海工程咨询行业协会
  • iis搭建多个网站网站前台
  • 建设厅官方网站职称做网站时的注册权起到什么作用
  • 学院网站建设的目的网页3d游戏排行榜
  • 冒用网站备案号建设网站网页制作设计课设报告
  • 企业网站设计特点家居网站建设素材
  • 太原自学网站建设wordpress 全屏浮动
  • 为外国人做非法网站城市建设模拟游戏登陆网站
  • 网站内页权重怎么查宁夏公路建设管理局网站
  • 西安php网站建设专家做汽车销售要了解的网站
  • 下载软件app排行榜穆棱seo
  • 最传统的网站推广手段wordpress快速开发
  • 网站建设吸引人的话语有哪些网站做的比较好的
  • 莆田外贸专业建站军队信息化建设网站