uniapp黑马商城从商品展示页跳转到商品详情页,传递goodsId

用到技术详解(通俗)
使用自定义事件,子组件(非页面)传值到父组件(index.页面)
父组件(tabbar页)使用uni.navigate传值给详情页
详情页通过onLoad来接收参数。
1.goods-list页,使用自定义事件传递id给index页面
<template>
    <view class="goods" >
        <view class="good" v-for="item in goods" :key="item.goods_id" @click="toDetail(item.goods_id)">
            <img class="img" :src="item.goods_small_logo" alt="" srcset="">
            <view class="font">
                <text class="price">¥{{item.goods_price}}</text>
                

                <text class="name">{{item.goods_name}}</text>
            </view>
        </view>
    </view>
</template>


<script>
    export default {
        props: ["goods"],
        data() {
            return {
                // goods: []
            }
        },
        methods: {
            toDetail(goodsId){
                this.$emit("toDetail",goodsId);
                console.log("goods-list",goodsId);
            }
        },
        onload(){
            this.getGoodsInfo()
        }
    }
</script>


<style lang="scss">
    .goods{
        width: 320px;
        display: flex;
        justify-content: space-around;
        flex-wrap: wrap;
        align-content: space-around;
        
        .good{
            margin-top: 5px;
            width: 150px;
            background-color: #ffffff;
            text-align: center;
            img{
                width: 130px;
                height: 185px;;
            }
            .font{
                width: 80%;
                font-size: 14px;
                .price{
                    color: red;
                }
            }
        }
    }
</style>

2.index.vue接收参数goodsId
<goodsList :goods="goods" @toDetail = "toDetail"></goodsList>

// 导航到商品详情页
            goGoodsDetail (goods_id) {
                uni.navigateTo({
                    url: '/pages/goods-detail/goods-detail?goods_id='+goods_id,
                })
            }

3.detail.vue接收goodsId,使用了页面周期函数
onLoad(option){
            console.log(option.goodsId)
        }

  • 0
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值