小程序(练习中)

主题颜色

在app.wxss中

page{
  --temeColor:#eb4450;
}

在 index.wxss中

view{
  /* 应用主题颜色 */
  color:var(--temeColor);
}

实现文字省略号css

display: -webkit-box;
overflow: hidden;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2; // 从第几行开始省略



overflow: hidden;  // 超出的文本隐藏
text-overflow: ellipsis; // 溢出用省略号显示
white-space: nowrap; // 溢出不换行
display: -webkit-box; // 将对象作为弹性伸缩盒子模型显示。
-webkit-line-clamp: 2; // 这个属性不是css的规范属性,需要组合上面两个属性,表示显示的行数。
-webkit-box-orient: vertical;  // 从上到下垂直排列子元素(设置伸缩盒子的子元素排列方式)

加入购物车数据放在本地缓存

// 商品信息
goodMsg:{},


// 加入购物车 点击事件
    handleCartAdd(){
        // 1.获取缓存中的购物车 数组
        // 2.判断商品数组是否存在于购物车数组中
        // 3.已存在  数据num++
        // 4.不存在  商品数组放入购物车数组
        // 5.把购物车重新添加回缓存中
        let cart = wx.getStorageSync('cart')||[]
        let index = cart.findIndex(v=>v.goods_id === this.goodMsg.goods_id)
        if(index !== -1){
            cart[index].num++
        }else{
            this.goodMsg.num = 1
            cart.push(this.goodMsg)
        }
        wx.setStorageSync('cart', cart)
        wx.showToast({
          title: '加入成功',
          icon:'success',
          mask:true
        })
    }

 微信小程序选择收货地址

// 选择收货地址
    // 取用户对小程序所授予获取地址的 权限状态scope
    // 1假设用户点击获取收货地址的提示框确定authSetting scope true直接调用获取收货地址
    // 2假设用户从来没有调用过收货地址的api             scope undefined 直接调用获取收货地址
    // 3假设用户点击获取收货地址的提示框取消            scope false
    //      诱导用户自己打开授权设置页面当用户重新给与获取地址权限的时候  获取收货地址
    handleChooseAddress() {
        wx.getSetting({
            success: (result) => {
                const address = result.authSetting['scope.address']
                if (address == true || address == undefined) {
                    wx.chooseAddress({
                        success: (result1) => {
                            console.log(result1);
                        },
                    })
                } else {
                    wx.openSetting({
                        success: () => {
                            wx.chooseAddress({
                                success: (result2) => {
                                    console.log(result2);
                                },
                            })
                        }
                    })
                }
            }

        })
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值