inkss
inkss
  • 发布:2024-12-25 10:24
  • 更新:2025-04-16 15:16
  • 阅读:87

【报Bug】微信小程序端vue3编译原生模块微信小店组件(store-product)异常

分类:uni-app

产品分类: uniapp/小程序/微信

PC开发环境操作系统: Mac

PC开发环境操作系统版本号: 1

HBuilderX类型: 正式

HBuilderX版本号: 4.29

第三方开发者工具版本号: 1.06.2412031

基础库版本号: 3.6.6

项目创建方式: HBuilderX

示例代码:

<template>
<view>
<view>{{ state.appid }}</view>
<template v-if="state.appid">
<store-product :appid="state.appid" :product-id="state.p_id" :key="state.appid" />
</template>
</view>
</template>
<script setup>
import { reactive } from 'vue'
const state = reactive({
appid: '123',
p_id: '123'
})
</script>

操作步骤:

<template>
<view>
<view>{{ state.appid }}</view>
<template v-if="state.appid">
<store-product :appid="state.appid" :product-id="state.p_id" :key="state.appid" />
</template>
</view>
</template>
<script setup>
import { reactive } from 'vue'
const state = reactive({
appid: '123',
p_id: '123'
})
</script>

预期结果:

希望编译后为<view><view>{{a}}</view><block wx:if="{{b}}"><store-product wx:if="{{d}}" key="{{c}}" u-i="390a71d8-0" bind:l="l" appid="{{a}}" product-id="{{b}}"/></block></view>

实际结果:

<view><view>{{a}}</view><block wx:if="{{b}}"><store-product wx:if="{{d}}" key="{{c}}" u-i="390a71d8-0" bind:l="l" u-p="{{d}}"/></block></view>

bug描述:

store-product为微信小店原生组件,被uniapp认为是自定义组件导致打包时组件上的属性丢失使微信小店组件无法正常展示
打包前的代码

<template>  
  <view>  
    <view>{{ state.appid }}</view>  
    <template v-if="state.appid">  
      <store-product :appid="state.appid" :product-id="state.p_id" :key="state.appid" />  
    </template>  
  </view>  
</template>  
<script setup>  
  import { reactive } from 'vue'  
  const state = reactive({  
    appid: '123',  
    p_id: '123'  
  })  
</script>

编译后的小程序wxml的代码
<view><view>{{a}}</view><block wx:if="{{b}}"><store-product wx:if="{{d}}" key="{{c}}" u-i="390a71d8-0" bind:l="l" u-p="{{d}}"/></block></view>
编译后index.js代码
"use strict";
const common_vendor = require("../../common/vendor.js");
if (!Array) {
const _component_store_product = common_vendor.resolveComponent("store-product");
_component_store_product();
}
const _sfc_main = {
name: "index",
setup(
props) {
const state = common_vendor.reactive({
appid: "123",
p_id: "123"
});
return (_ctx, _cache) => {
return common_vendor.e({
a: common_vendor.t(state.appid),
b: state.appid
}, state.appid ? {
c: state.appid,
d: common_vendor.p({
appid: state.appid,

    })  
  } : {});  
};  

}
};
const MiniProgramPage = / @PURE / common_vendor._export_sfc(_sfc_main, [["__file", "/Users/takechuanmei/Desktop/code/yuelin-strict-selection-mp/src/pages/test/index.vue"]]);
wx.createPage(MiniProgramPage);

2024-12-25 10:24 负责人:无 分享
已邀请:
DCloud_UNI_yuhe

DCloud_UNI_yuhe

参考一下这个问题试试 https://ask.dcloud.net.cn/question/207749

要回复问题请先登录注册