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

视频直播网站建设费用建设公司网站的意义

视频直播网站建设费用,建设公司网站的意义,用npp做网站,企业员工管理培训课程一、商品详情 1、从商品列表页跳转到商品详情页 在商品列表的项中绑定单击事件&#xff0c;并传递商品id值 <view class"goods-item" v-for"(item,index) in goodsList" :key"index" click"goGoodsDetail(item.goods_id)"> &…

一、商品详情

1、从商品列表页跳转到商品详情页

  • 在商品列表的项中绑定单击事件,并传递商品id值

<view class="goods-item" v-for="(item,index) in goodsList" :key="index" @click="goGoodsDetail(item.goods_id)">
</view>
  • 在methods选项中定义goGoodsDetail方法实现跳转到商品详情页

goGoodsDetail(goods_id){uni.navigateTo({url:`/pages/goodsdetail/index?goods_id=${goods_id}`})
}

2、获取商品详情数据

  • 在data中定义商品详情的数据

data() {return {goods_item:{}}
}
  • onLoad 中获取商品的 Id,并调用请求商品详情的方法

onLoad(options) {let gid=options.goods_idthis.getGoodsById(gid)
}
  • methods 中声明 getGoodsById 方法:

methods: {async getGoodsById(goods_id){let result=await uni.$api.get('/goods/detail',{goods_id:goods_id})this.goods_item=result.data.message}
},

3、渲染商品轮播图区域

  • 渲染轮播图区域

<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" class="swiper"><swiper-item v-for="(item,index) in goods_item.pics" :key="index"><image :src="item.pics_big"></image></swiper-item>
</swiper>
<style lang="scss">.swiper{height: 750rpx;image{width: 100%;height: 100%;}}
</style>
  • 完成轮播图预览功能

为轮播图中的 image 图片绑定 click 事件处理函数:

<swiper-item v-for="(item,index) in goods_item.pics" :key="index"><image :src="item.pics_big" @click="perview(index)"></image>
</swiper-item>

methods 中定义 preview 事件处理函数:

perview(index){uni.previewImage({current:index,urls:this.goods_item.pics.map(item=>item.pics_big)})
}

4、渲染商品信息区域

<view class="goods-info-box"><!-- 商品价格 --><view class="price">¥{{goods_item.goods_price}}</view><!-- 信息主体区域 --><view class="goods-info-body"><!-- 商品名称 --><view class="goods-name">{{goods_item.goods_name}}</view><!-- 收藏 --><view class="favi"><uni-icons type="star" size="18" color="gray"></uni-icons><text>收藏</text></view></view><!-- 运费 --><view class="yf">快递:免运费</view>
</view>
<rich-text :nodes="goods_item.goods_introduce"></rich-text>
.goods-info-box {padding: 10px;padding-right: 0;.price {color: #c00000;font-size: 18px;margin: 10px 0;}.goods-info-body {display: flex;justify-content: space-between;.goods-name {font-size: 13px;padding-right: 10px;}// 收藏区域.favi {width: 120px;font-size: 12px;display: flex;flex-direction: column;justify-content: center;align-items: center;border-left: 1px solid #efefef;color: gray;}}// 运费.yf {margin: 10px 0;font-size: 12px;color: gray;}}

5、渲染详情页底部的商品导航区域

在 data 中,通过 optionsbuttonGroup 两个数组,来声明商品导航组件的按钮配置对象

data(){return{options: [{icon: 'shop',text: '店铺'}, {icon: 'cart',text: '购物车',info: 2}],// 右侧按钮组的配置对象buttonGroup: [{text: '加入购物车',backgroundColor: '#ff0000',color: '#fff'},{text: '立即购买',backgroundColor: '#ffa200',color: '#fff'}]}
}

在页面中使用 uni-goods-nav 商品导航组件:

<view class="goods_nav"><uni-goods-nav :fill="true"  :options="options" :buttonGroup="buttonGroup"  @click="onClick" @buttonClick="buttonClick" />
</view>

美化商品导航组件,使之固定在页面最底部:

.container{padding-bottom: 100rpx;
}
.goods_nav {// 为商品导航组件添加固定定位position: fixed;bottom: 0;left: 0;
}

二、加入购物车

1、下载vuex

npm i vuex@3.6.2

2、配置Vuex

  • 在src下创建store文件夹,在store文件夹下创建index.js文件

import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store=new Vuex.Store({modules:{}
})
export default store
  • 在main.js将store对象挂载到Vue的实例上

import store from '@/store/index.js'
const app = new Vue({...App,store
})
app.$mount()

3、创建购物车模块

  • 在store/modules目录下创建shopcart.js文件

export default{namespaced:true,state:{shopcartList:[]},mutations:{},getters:{}
}
  • store/index.js 模块中,导入并挂载购物车的 vuex 模块

import Vue from 'vue'
import Vuex from 'vuex'
import shopart from '@/store/modules/shopcart.js'
Vue.use(Vuex)
const store=new Vuex.Store({modules:{shopart}
})
export default store

4、在商品详情中使用store中的数据

import {createNamespacedHelpers} from 'vuex'
const {mapState:mapShopcartState}=createNamespacedHelpers('shopart')
export default {computed:{...mapShopcartState(['shopcartList'])}
}

5、实现加入购物车的功能

  • 编写一个加入购物车的方法的mutations方法addToShopcart方法

export default{namespaced:true,state:{shopcartList:[]},mutations:{addToShopart(state,goods){const result=state.shopcartList.find(item=>item.goods_id==goods.goods_id)if(!result){state.shopcartList.push(goods)}else{goods.goods_count++}}},getters:{}
}
  • 在商品详情页面中,通过 mapMutations 这个辅助方法,把 vuex 中 shopcart 模块下的 addToShopart 方法映射到当前页面:

import {createNamespacedHelpers} from 'vuex'
const {mapState:mapShopcartState,mapMutations:mapShopcartMutations}=createNamespacedHelpers('shopart')
export default{methods:{...mapShopcartMutations(['addToShopart']),}
}
  • 为商品导航组件 uni-goods-nav 绑定 @buttonClick="buttonClick" 事件处理函数:

buttonClick(e){if(e.content.text=='加入购物车'){const goods = {goods_id: this.goods_item.goods_id,       goods_name: this.goods_item.goods_name,   goods_price: this.goods_item.goods_price, goods_count: 1,                          goods_small_logo: this.goods_item.goods_small_logo, goods_state: true                         }this.addToShopart(goods)}
}

6、动态统计购物车中商品的总数量

getters 节点下定义一个 total 方法,用来统计购物车中商品的总数量:

getters:{total(state){return state.shopcartList.reduce((prev,cur)=>prev+cur.goods_count,0)}
}
  • 导入 mapGetters 方法并进行使用

import {createNamespacedHelpers} from 'vuex'
const {mapGetters:mapShopcartGetters}=createNamespacedHelpers('shopart')
export default{computed:{...mapShopcartGetters(['total'])},
}
  • 通过 watch 侦听器,监听计算属性 total 值的变化,从而动态为购物车按钮的徽标赋值

watch:{total:{handler(newval){let result=this.options.find(item=>item.text==="购物车")if(result){result.info=newval}},immediate:true}
},

7、持久化购物车中的商品

修改 mutations 节点中的 addToCart 方法,在处理完商品信息后,调用 saveToStorage 方法:

mutations:{addToShopart(state,goods){const result=state.shopcartList.find(item=>item.goods_id==goods.goods_id)if(!result){state.shopcartList.push(goods)}else{goods.goods_count++}uni.setStorageSync('cart',JSON.stringify(state.shopcartList))},},

修改 shopcart.js 模块中的 state 函数,读取本地存储的购物车数据,对 shopcartList 数组进行初始化

state:{shopcartList:JSON.parse(uni.getStorageSync('cart')||'[]')
}

三、购物车列表

1、购物车列表

<template><view class="container"><view v-for="(goods,index) in shopcartList" :key="index" class="goods-item"><view class="goods-item-left"><radio checked color="#C00000"></radio><image :src="goods.goods_small_logo" class="goods-pic"></image></view><view class="goods-item-right"><view class="goods-name">{{goods.goods_name}}</view><!-- 商品价格 --><view class="goods-price">¥{{goods.goods_price}}</view><!-- 商品数量 --><uni-number-box :min="1"></uni-number-box></view></view></view>
</template><script>import {createNamespacedHelpers} from 'vuex'const {mapState: mapShopcartState,mapMutations: mapShopcartMutations,mapGetters: mapShopcartGetters} = createNamespacedHelpers('shopart')export default {data() {return {}},methods: {},computed: {...mapShopcartState(['shopcartList'])}}
</script><style lang="scss">.container {.goods-item {display: flex;margin: 20rpx 10rpx;.goods-item-left {margin-right: 5px;display: flex;justify-content: space-between;align-items: center;.goods-pic {width: 100px;height: 100px;display: block;}}.goods-item-right {.goods-price{color: #C00000;}}}}
</style>

2、修改购物车商品的勾选状态

  • 给shopcart.js模块中的mutations选项中添加修改购物车状态的方法

mutations:{updateShopcartState(state,goods){const result=state.shopcartList.find(item=>item.goods_id==goods.goods_id)if(result){result.goods_state=!goods.goods_state}uni.setStorageSync('cart',JSON.stringify(state.shopcartList))}
},
  • 在购物车列表页面中进行访问

methods: {...mapShopcartMutations(['updateShopcartState']),radioChange(goods){this.updateShopcartState(goods)}
},

3、修改购物车商品数量的方法

给shopcart.js模块中的mutations选项中添加修改s购物车数量的方法的方法

mutations:{updateShopcartNum(state,goods){const result=state.shopcartList.find(item=>item.goods_id==goods.goods_id)if(result){result.goods_count=goods.goods_count}uni.setStorageSync('cart',JSON.stringify(state.shopcartList))}
},
  • 在uni-number-box绑定change事件

<uni-number-box :min="1" :value="goods.goods_count" @change="numChange($event,goods)"></uni-number-box>
  • 在购物车列表页面中进行访问

methods: {...mapShopcartMutations(['updateShopcartState','updateShopcartNum']),radioChange(goods){this.updateShopcartState(goods)},numChange(e,val){this.updateShopcartNum({goods_id:val.goods_id,goods_count:e})}
},
http://www.yayakq.cn/news/772553/

相关文章:

  • 网站小视频怎么做代理商seo赚钱吗
  • 如何推广手机网站淮北矿业集团工程建设公司网站
  • 深圳专业网站设计公司哪家好wordpress add_role
  • 世界工厂采购网站过期域名
  • 浙江职业能力建设网站网页制作代码html
  • 企业网站建设ejiew小程序制作合同模板
  • 有意思的网站软件定制开发价格
  • 做网站制作挣钱吗网站建设公司一般用什么建站系统
  • 电子商务网站首页目前最新推广平台
  • 南京网站推广¥做下拉去118crwordpress只显示标题
  • 微网站开发方案模板外贸平台app下载
  • 网站模板免费下载网站平度好的建设网站
  • 什么渠道做网站建设徐州商城网站建设
  • 深圳网站建设服务哪个便宜啊盐城网站定制
  • 有域名后怎么做网站广州平面设计
  • 在哪个网站注册公司医院网站icp备案吗
  • 网站开发运营新人要注意什么廊坊自动seo
  • 网站设计字体大小wordpress百度主动不推送了
  • 做漫画视频在线观看网站中山大兴网站建设
  • 虚拟主机和网站空间河北营销型网站方案
  • 网站系统建设申请报告哈德网站建设
  • 商丘网站iphone8多少钱
  • 开福区城乡建设局门户网站企业管理咨询服务有限公司
  • 高明专业网站建设哪家好苏州网站建设系统价格合理
  • 天津网站建设营销型网站重要性
  • 网站开发js不更新江苏省交通建设监理协会网站
  • 西安英文网站建设1号店网上购物商城
  • 厂 网站 南宁河北城乡建设学校网站
  • 电商网站建设策划书360crm客户管理系统
  • 龙采哈尔滨建站公司济南logo设计制作