uni-app 报Bug where:方式1. 使用模板字符串,用${}包裹变量 bug

uni-app 报Bug where:方式1. 使用模板字符串,用${}包裹变量 bug

示例代码:

<unicloud-db ref="udb" collection="hamsters_album" v-slot:default="{data,loading,error}"   
where="<code>username=='${tempstr}'</code>"
        orderby="create_time desc"
        @load="handleLoad"
        >
    <view v-if="loading">加载中...</view>
    <view v-if="error">加载错误</view>
</unicloud-db>

操作步骤:

<unicloud-db ref="udb" collection="hamsters_album" v-slot:default="{data,loading,error}"   
where="<code>username=='${tempstr}'</code>"
        orderby="create_time desc"
        @load="handleLoad"
        >
    <view v-if="loading">加载中...</view>
    <view v-if="error">加载错误</view>
</unicloud-db>

预期结果:

  • 正常where语句

实际结果:

[WXML 文件编译错误] ./pages/index/photo/photo.wxml
Bad attr <code>where</code> with message 
1 | <view><block wx:if="{{isUpdate}}"><drag-button vue-id="2f197fb7-1" isDock="{{true}}" margTop="{{100}}" existTabBar="{{true}}" imgSrc="{{dragSrc}}" data-event-opts="{{[['^btnClick',[['e0']]]]}}" bind:btnClick="e" bind:l="l"></drag-button></block></view><u-action-sheet vue-id="2f197fb7-2" list="{{listSheet}}" value="{{UmodalShow}}" data-event-opts="{{[['^click',[['clickSheet']]],['^input',[['set_model',['','UmodalShow','$event',[]]]]]]}}" bind:click="e" bind:input="e" bind:l="l"></u-action-sheet><view><view><view class="u-padding-top-20"><cus-pets-avatar vue-id="2f197fb7-3" hamsterData="{{hamsterData}}" bind:l="l"></cus-pets-avatar></view></view></view><view><tool-uploader-img class="vue-ref" vue-id="2f197fb7-4" buttonStyle="{{uploaderButtonStyle}}" data-ref="refUploader" data-event-opts="{{[['^uploadPath',[['uploadPath']]]]}}" bind:uploadPath="e" bind:l="l"></tool-uploader-img><unicloud-db generic:scoped-slots-default="photo-unicloud-db-default" data-vue-generic="scoped" class="vue-ref" vue-id="2f197fb7-5" collection="hamsters_album" where="{{'username==\''+tempstr+'\''}}" orderby="create_time desc" data-ref="udb" data-event-opts="{{[['^load',[['handleLoad']]]]}}" bind:load="e" bind:l="l" vue-slots="{{['default']}}"></unicloud-db></view></view>
^
at

bug描述:

  • where:方式1. 使用模板字符串,用${}包裹变量
  • 复制的官方的,小程序平台为啥报错!!!

更多关于uni-app 报Bug where:方式1. 使用模板字符串,用${}包裹变量 bug的实战教程也可以访问 https://www.itying.com/category-93-b0.html

3 回复

没复制对,where前面有:,里面有``

更多关于uni-app 报Bug where:方式1. 使用模板字符串,用${}包裹变量 bug的实战教程也可以访问 https://www.itying.com/category-93-b0.html


微信开发工具解析有问题,可以先把where写在computed里。后续我们会兼容一下

在uni-app中使用unicloud-db组件时,where条件中使用模板字符串的方式在小程序平台确实会报错。这是因为小程序平台的WXML模板语法和Vue模板语法存在差异。

正确的写法应该是使用Vue的绑定语法,将where条件作为JavaScript表达式处理:

<unicloud-db ref="udb" collection="hamsters_album" v-slot:default="{data,loading,error}"   
:where="`username=='${tempstr}'`"
orderby="create_time desc"
[@load](/user/load)="handleLoad">
    <view v-if="loading">加载中...</view>
    <view v-if="error">加载错误</view>
</unicloud-db>
回到顶部