dcloudio / uni-app

A cross-platform framework using Vue.js
https://uniapp.dcloud.io
Apache License 2.0
39.64k stars 3.6k forks source link

v-for + slot会出现大量警告以及无法正常渲染。 #4652

Open frankcou opened 6 months ago

frankcou commented 6 months ago

问题描述 v-for + slot会出现大量警告以及无法正常渲染。

续上https://github.com/dcloudio/uni-app/issues/3503#issue-1233360215

我尝试过npx @dcloudio/uvm@latest 2.0.2-3071120230427001,出现Invalid version: 2.0.2-3071120230427001(也就是说没这个版本了)

查了npm上的版本,甚至尝试过3.0.0-alpha-4000020231227002这个最新版本,依然无法解决问题

补充信息

  1. v-for+slot的修复现在还没合并上去么?
  2. 我见微信小程序上开始支持多个相同slot写法,不知道支持了glass-easel框架了没,https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/glass-easel/dynamic-slots.html
zhetengbiji commented 6 months ago

3503 反馈的问题,以及讨论中所涉及的版本和修复都是针对 vue2 的。从你回答中提到的版本号判断,你可能使用的是 vue3 的需要另行排查。

zhetengbiji commented 6 months ago

关于 glass-easel 框架,目前还未单独处理,你可以尝试自行启用和验证。

frankcou commented 6 months ago

3503 反馈的问题,以及讨论中所涉及的版本和修复都是针对 vue2 的。从你回答中提到的版本号判断,你可能使用的是 vue3 的需要另行排查。

确实是使用的vue3。不知道我不使用cli,直接使用HBuilder会不会就不会有这个问题?@zhetengbiji

zhetengbiji commented 6 months ago

3503 反馈的问题,以及讨论中所涉及的版本和修复都是针对 vue2 的。从你回答中提到的版本号判断,你可能使用的是 vue3 的需要另行排查。

确实是使用的vue3。不知道我不使用cli,直接使用HBuilder会不会就不会有这个问题?

如果对版本无明确的要求可以直接执行 npx @dcloudio/uvm@latest 升级到最新版 。 如果升级后仍然存在该问题,可以详细描述一下,方便验证和排查。

frankcou commented 6 months ago

首页 pages/index.vue

<template>
  <view class="page content">
      <parent>
        <template v-slot:parentslot="{ item }">
          <view> {{ item }} </view>
        </template>
      </parent>
  </view>
</template>

<script setup lang="ts">
import { onMounted, ref } from "vue";
import parent from "@/components/parent/parent.vue";
defineOptions({
  multipleSlots: true,
  dynamicSlots: true,
});
</script>

组件components/parent/parent.vue

<template>
  <view class="parent">
    <child>
      <template v-slot:childslot="{ item }">
        <slot name="parentslot" :item="item"></slot>
      </template>
    </child>
  </view>
</template>

<script setup lang="ts">
import child from "./child.vue";
</script>

组件components/parent/child.vue

<template>
  <view class="child">
    <view v-for="item in arr" :key="item">
      <slot name="childslot" :item="item"></slot>
    </view>
  </view>
</template>

<script setup lang="ts">
import { ref } from "vue";
const arr = ref([1, 2, 3]);
</script>

目前使用的调试基础库是3.2.5

报错信息

[Component] More than one slot named "parentslot" are found inside a single component instance (in component "components/parent/parent"). The first one was accepted.

首页编译出来的结果是

<view class="page content data-v-83a5a03c">
  <parent class="data-v-83a5a03c" u-s="{{['parentslot']}}" u-i="83a5a03c-0" bind:__l="__l">
    <view wx:for="{{a}}" wx:for-item="v0" wx:key="b" slot="{{v0.c}}">
      <view class="data-v-83a5a03c">{{v0.a}}</view>
    </view>
  </parent>
</view>

@zhetengbiji

wlj0924 commented 4 weeks ago

楼主解决了没,同样的问题

wlj0924 commented 4 weeks ago

正常嵌套两层slot展示正常,如果第三层slot展示有问题,只展示最后那个循环的数据