wepy关于微信小程序的一点踩坑

本文探讨了在Wepy框架中遇到的组件生命周期问题,指出组件只存在onLoad周期,并详细解析了本地路径无效的情况,建议使用网络路径。同时,针对图片加载错误,文章提供了处理方法,包括图片尺寸计算和错误回调。此外,还提及了父组件传递数据时可能出现的字段缺失问题及其应对方案。
摘要由CSDN通过智能技术生成

1.wepy组件只有onLoad生命周期

2.wepy组件url路径只能导入网络路径,本地路径无效

<style scoped lang="scss">
    .empty-placeholder {
        padding-top: 290rpx;
        width: 100%;
        text-align: center;
        .emptyImg{
            width: 203rpx;
            display: block;
            margin: 0 auto;
        }
        .txt {
            font-size: 26rpx;
            color: #848484;
            margin-top: 26rpx;
        }
    }

</style>
<template>
    <view class="empty-placeholder" wx:if="{{show}}">
        <image class="emptyImg" wx:if="{{emptyInfo[type].icon}}" src="{{emptyInfo[type].icon}}" bindload="getImgSize" binderror="getError" style="height: {{height}}rpx" />
        <view class="txt">{{emptyInfo[type].text}}</view>
    </view>
</template>
<script>
import wepy from "wepy";
export default class Placeholder extends wepy.component {
  props = {
    show: {
      type: Boolean,
      default: false
    },
    type: String,
  };
  data = {
      height:0,
      emptyInfo:{
          qd:{
              // icon:"../images/img/c1@2x.png",无效,请使用网络路径
              icon:wepy.$instance.globalData.cloudPath + "/myCase/noCase.png",
              text:"暂无清单信息",
          }
      },
  }
    methods = {
        getImgSize(e){
            console.log(e,"e")
            let {width,height} = e.detail;
            let scale;
            if(width > height){
                scale = width/height;
            }else {
                scale = height/width;
            }
            this.height = 203/scale;
        },
        getError(e){
            console.log("图片载入失败触发",e)
            /*this.emptyInfo[this.type].icon = this.emptyInfo[this.type].icon + " "
            this.$apply();
            console.log(this.emptyInfo[this.type].icon,"啦啦啦啦")*/
        }
   }
}
</script>

3.报错:

 element parse error: Error invalid tagName: @#[line:1,col:3]

组件中用了某个属性,但是父组件传过来的数据里面没有改字段

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值