小程序wx:else提示 Bad attr `wx

 问题:以下wx:for里的wx:if , wx:else 会报这个错:Bad attr 'wx

  <scroll-view class="scroll1" scroll-x enable-flex="true">

        <view wx:if="{
   
   {playlist.length>0}}" class="item" wx:for="{
   
   {playlist}}" >
          <image class="item-img" src="{
   
   {item.song.al.picUrl?item.song.al.picUrl:'/static/images/recommendSong/02.jpg'}}"></image>
          <text class="item-value">{
   
   {item.song.al.name}}</text>
        </view>
        <view wx:else> 暂无播放记录</view>

      </scroll-view>

 解决:

WX:FOR和WX:IF在同一个标签下提:for的优先级比if的优先级要高,wx:if 与wx:for 不能写在同一个标签上,按如下代码个性,增加一个block包裹:

      <scroll-view class="scroll1" scroll-x enable-flex="true">
        <block wx:if="{
   
   {playlist.length>0}}">
          <view  class="item" wx:for="{
   
   {playlist}}" >
            <image class="item-img" src="{
   
   {item.song.al.picUrl?item.song.al.picUrl:'/static/images/recommendSong/02.jpg'}}"></image>
            <text class="item-value">{
   
   {item.song.al.name}}</text>
          </view>
        </block>
        <view wx:else> 暂无播放记录</view>
      </scroll-view>

猜你喜欢

转载自blog.csdn.net/LlanyW/article/details/132129228