最近公司决定对公司最重要的小程序(约40W用户)进行项目重构,换掉原有的 wepy 框架改成uniapp 形式方便后续做抖音小程序之类的。以下是我遇到的部分小问题,希望可以帮助成长路上迷茫的你!
问题一:样式绑定写法
wepy 原生微信小程序:
<view class="top_title" style="padding-top: {{top}}px;">个人中心</view>
<view bindtap="tabClick({{idx}})" class="scroll-view-item {{idx== index ? 'active' : ''}} {{employeeday.busy ? 'busy' : ''}}" >
uniapp微信小程序:
<view class="top_title" :style="{'padding-top': top + 'px','padding-bottom':(showDiv ? '15px' : '')}" >个人中心</view>
<view bindtap="tabClick({{idx}})" :class="['scroll-view-item',idx==index ? 'active' : '' , employeeday.busy ? 'busy' : '']" >
问题二:repeat 标签的替换
wepy 原生微信小程序:
<repeat for="{{employeedays[index].houres}}" index="idxChild" key="{{hour.id}}" item="hour">
<view class="time_one">
<view wx:if="{{hour.disable== 1}}" class="time orange">{{hour.time}}</view>
<view wx:if="{{hour.disable== 0}}" class="time disabled" >{{hour.time}</view>
<view wx:if="{{hour.disable== 3}}" class="time active" @tap="checkDate({{idxChild}},{{index}})">{{hour.time}}</view>
<view wx:if="{{hour.disable== 2}}" class="time" @tap="checkDate({{idxChild}},{{index}})">{{hour.time}}</view>
<view wx:if="{{hour.disable== 1 }}" class="time_label">已约满</view>
<view wx:if="{{hour.disable== 0 }}" class="time_label">不可约</view>
</view>
</repeat>
因为 repeat 标签是 wepy 框架的,所以重构以后不得不更换。这会导致 v-for 循环的内容样式错位,所以写法会有一点改变,相应的样式也需要做一些调整,关于样式这里就不和大家过多说明了。
uniapp微信小程序:
<view v-for="(hour,idxChild) in employeedays[index].houres" :key="hour.id" class="time_one">
<view v-if="hour.disable== 0" class="time disabled" >{{hour.time}}</view>
<view v-if="hour.disable== 3" class="time active" @tap="checkDate(idxChild,index)">{{hour.time}}</view>
<view v-if="hour.disable== 2" class="time" @tap="checkDate(idxChild,index)">{{hour.time}}</view>
<view v-if="hour.disable== 1" class="time orange">{{hour.time}}</view>
<view v-if="hour.disable== 1" class="time_label">已约满</view>
<view v-if="hour.disable== 0" class="time_label">不可约</view>
</view>
特别注意:换成 v-for 以后不要习惯性的直接 item in XXX,看看差值里面的东西再来决定item的名称。否则会渲染出很多 undefined !