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

怎么做二次元网站源码河南网站seo地址

怎么做二次元网站源码,河南网站seo地址,长沙建设网站,做类似淘宝一样的网站让我们利用所学知识来开发一个简单的购物车 #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.w-s-a.com/news/44978/

相关文章:

  • 系部网站建设中期检查表创建网站的公司
  • 西宁网站建设优化重庆企业的网站建设
  • 贝壳企业网站管理系统徽与章网站建设宗旨
  • 郑州网站模板动漫设计与制作设计课程
  • 在线制作网站的工具岳阳网站设计改版
  • 网站建设需要汇报哪些内容前端开发的工作内容
  • 无锡阿凡达网站建设美团app开发公司
  • 个性化企业网站制作公司深圳高端网站定制公
  • 专业深圳网站定制开发企业网站开发 流程
  • 网站建设推广的软文php网站平台
  • 如何做代刷网站长外贸网站个性设计
  • 合同网站开发 设计 后期维护如何搭建海外网络
  • 提供网站建设服务优化大师哪个好
  • 军队营房基础建设网站哦咪咖网站建设
  • fifa17做任务网站app下载免费安装
  • 网站开发用哪些技术seo是什么意思为什么要做seo
  • 网站会动的页面怎么做的与网站建设有关的招标文件
  • 公司网站如何做seowordpress付费资源
  • 福田做商城网站建设哪家公司便宜点WordPress安装子目录
  • 南京建设交易中心网站wordpress 拼车
  • 上海今天发生的重大新闻5条河南网站seo费用
  • 广东深圳最新情况临安网站seo
  • 华为快速建站女人做春梦网站
  • 建外贸网站费用手机排行榜zol
  • 长治网站制作的网站做网站要什么知识条件
  • discuz 做门户网站wordpress怎么添加图片不显示图片
  • 东营网站建设方案范文百度应用搜索
  • 网站 常见推广js代码放wordpress哪里
  • 靖江网站开发徐州住房和城乡建设局网站
  • 南宁网站建设公司如何为老板打造网站赚钱的wordpress optimizer