NervJS / taro

开放式跨端跨框架解决方案,支持使用 React/Vue/Nerv 等框架来开发微信/京东/百度/支付宝/字节跳动/ QQ 小程序/H5/React Native 等应用。 https://taro.zone/
https://docs.taro.zone/
Other
35.61k stars 4.8k forks source link

动态组件component在v-for循环中可能出现问题 #11484

Open vform666 opened 2 years ago

vform666 commented 2 years ago

相关平台

微信小程序

小程序基础库: 2.14.4 使用框架: Vue 3

复现步骤

<template>
  <view class="index">
    <view>
      <img src="" alt="">
    </view>
    {{ msg }}
    <view class="btn">
      <nut-button type="primary" @click="handleClick('text', msg2, true)">点我</nut-button>
      <component :is="testButton">aaaa</component>

      <template v-for="comp in customComponents">
        <component :is="comp.type">aaaa</component>
      </template>
    </view>
    <nut-toast :msg="msg" v-model:visible="show" :type="type" :cover="cover" />
  </view>
</template>

<script>
import { reactive, ref, toRefs } from 'vue';
export default {
  name: 'Index',
  components: {

  },
  setup(){
    const state = reactive({
      msg: '欢迎使用 NutUI3.0 开发小程序',
      msg2: '你成功了~',
      type: 'text',
      show: false,
      cover: false
    });

    const testButton = ref('nut-button')

    let customComponents = reactive([
      {type: 'nut-buttton', label: '按钮1'},
      {type: 'nut-buttton', label: '按钮2'},
    ])

    const handleClick = (type, msg, cover = false) => {
      state.show = true;
      state.msg2 = msg;
      state.type = type;
      state.cover = cover;
    };

    return {
      ...toRefs(state),
      testButton,
      customComponents,
      handleClick
    }
  }
}
</script>

期望结果

动态组件能正常渲染

实际结果

报错:

 Template `tmpl_0_nut-buttton` not found.
  347 | 
  348 | <template name="tmpl_2_container">
> 349 |   <template is="{{xs.a(2, i.nn, l)}}" data="{{i:i,cid:2,l:xs.f(l,i.nn)}}" />
      |                ^
  350 | </template>
  351 | 
  352 | <template name="tmpl_3_catch-view">

环境信息

 Taro v3.4.3

  Taro CLI 3.4.3 environment info:
    System:
      OS: Windows 10
    Binaries:
      Node: 16.13.0 - C:\Program Files\nodejs\node.EXE        
      Yarn: 1.22.17 - C:\Users\jc\AppData\Roaming\npm\yarn.CMD
      npm: 8.1.0 - C:\Program Files\nodejs\npm.CMD
github-actions[bot] commented 2 years ago

等待热心的小伙伴解决问题中..., 有一些相关的 issues 可能帮助到你!

Thank you so much!