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

北京中御建设公司网站网络营销方案论文

北京中御建设公司网站,网络营销方案论文,网站未建设的情况说明,企业网站服务器选择让我们利用所学知识来开发一个简单的购物车 &#xff08;记得暴露属性和方法&#xff01;&#xff01;&#xff01;&#xff09; 首先来看一下最基本的一个html框架 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"&…

让我们利用所学知识来开发一个简单的购物车

(记得暴露属性和方法!!!)

首先来看一下最基本的一个html框架

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>实战小项目:购物车</title><style>body {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>
<body><div id="app"><h1>实战小项目:购物车</h1><!-- 提示:可以使用v-for指令,假设有n个品类,则生成n个商品项--><div class="cart-item"><div class="buttons"><span>苹果 &nbsp;&nbsp;</span><button>-</button><span class="quantity">1&nbsp;&nbsp;</span><button>+</button><p>请输入价格:<input type="text"/> 元/斤 <br> 单价:1 元/斤</p></div></div><!-- 提示:可以用计算属性或数据变动侦听器,跟踪商品数和单价的变化,进而求出总数和总价--><h3>商品总数:  <ins> 1 </ins> 件</h3><h3>商品总价:  <ins> 1 </ins> 元</h3></div><script type="module">import { createApp, reactive, computed } from './vue.esm-browser.js'createApp({setup() {// 1.定义属性:存储商品的(响应式)数组 // 2.定义方法:增加商品数// 3.定义方法:减少商品数// 4.定义方法:计算商品总数// 5.定义方法:计算商品总价// 6.暴露属性和方法}}).mount('#app');</script>
</body>
</html>

效果如下:

目前是一个静态的一个网页

首先定义属性:存储商品的(响应式)数组(使用v-for遍历

  <div class="cart-item" v-for="(item,index) in cartItems">const 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)">-</button><span class="quantity">{{cartItems[index].quantity}} &nbsp;&nbsp;</span><button v-on:click = "next(index)">+</button>// 2.定义方法:增加商品数const next = (index) =>{cartItems[index].quantity ++;}                             // 3.定义方法:减少商品数const pre = (index) => {if ( cartItems[index].quantity>1) {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 type="text" v-model="cartItems[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 lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>实战小项目:购物车</title><style>body {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>
<body><div id="app"><h1>实战小项目:购物车</h1><!-- 提示:可以使用v-for指令,假设有n个品类,则生成n个商品项--><div class="cart-item" v-for="(item,index) in cartItems"><div class="buttons"><span>{{item.name}}&nbsp;&nbsp;</span><button v-on:click = "pre(index)">-</button><span class="quantity">{{cartItems[index].quantity}} &nbsp;&nbsp;</span><button v-on:click = "next(index)">+</button><p>请输入价格:<input type="text" v-model="cartItems[index].unit_price"> 元/斤 <br> 单价:1 元/斤</p></div></div><!-- 提示:可以用计算属性或数据变动侦听器,跟踪商品数和单价的变化,进而求出总数和总价--><h3>商品总数:  <ins> {{totalItem()}} </ins> 件</h3><h3>商品总价:  <ins> {{totalprice}}</ins> 元</h3></div><script type="module">import { createApp, reactive, computed } from './vue.esm-browser.js'createApp({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].quantity>1) {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.yayakq.cn/news/431284/

相关文章:

  • 家做网站知名网络软文推广平台
  • 中国建设银行官方网站登录入口wordpress 定制缩略图
  • 网站设计的基本方法wordpress更换后台登录界面logo
  • 乐清案例上传网站政务公开与网站建设的矛盾
  • ip开源网站fpga可以做点什么用广西房管局官网
  • 四川自助seo建站辽宁网站优化
  • 数据库网站开发外文翻译建设自己的网站有钱赚么
  • 网站制作网站建设案例青岛贸易公司 网站制作
  • 北京网站开发不限年龄江西响应式网页建设
  • 南京做网站seo的无网站做cpa
  • 2017年网站建设市场分析如何拥有自己的网站
  • 南平购物网站开发设计自己家的电脑宽带50m做网站服务器
  • 企业网站建设论文模板wordpress评论采集发布
  • 如何免费建设公司网站制作精美网站建设口碑好
  • 怎么在南京人社网站做失业登记wordpress怎样创建门户网站
  • 建立企业网站选什么好广州公司注册多少钱
  • 湘潭做网站口碑好磐石网络旅游地网站制作
  • 做钓鱼网站会被抓判刑吗云南楚雄旅游必去的景点
  • 织梦企业网站管理系统黄聪wordpress
  • 设计网站公司力荐亿企邦成都网站建设天府科蓝
  • 营销型企业网站建设的预算跨境电商 网站开发
  • 如何做强一个网站的品牌wordpress 响应 主题
  • 网站域名每年费用中国建筑出国招聘网
  • 好看的美食怎么做视频网站买空间网
  • 网站建设页面大小做物流网站
  • 网站建设 思维导图企业如何数字化转型
  • 南阳市网站建设阿里云域名注册步骤
  • 对做网站有什么建议WordPress会员注册管理
  • 虚拟主机与网站建设网站网络安全怎么做
  • 行业网站排名张家港城市建设规划局网站