Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vue3微信小程序v-for动态绑定插槽解析问题 #5269

Open
c-sopoo opened this issue Dec 24, 2024 · 6 comments
Open

Vue3微信小程序v-for动态绑定插槽解析问题 #5269

c-sopoo opened this issue Dec 24, 2024 · 6 comments
Assignees

Comments

@c-sopoo
Copy link

c-sopoo commented Dec 24, 2024

组件模板:

<template v-for="(col, i) in columns" :key="col.prop">
      <view
        class="table-body-cell cell"
        :class="[`cell-fixed-${col.fixed}`]"
        :style="{ width: col.width, textAlign: col.align }"
      >
        <view class="cell-wrapper">
          <view class="cell-content stock-item-content f32" :class="col.prop">
            <!-- 自定义插槽 -->
            <template v-if="col.slot && $slots[col.slot]">
              <slot :name="col.slot" :data="dataItem"></slot>
            </template>
            <template v-else>
              <view>2</view>
......

image

使用组件:

<template v-for="item in stocks[currentTabItem.id]" :key="item.code">
        <stock-table-row  :dataItem="item">
          <template #name="{ data }">
            <view class="stock-name flex y">
              123
              <view>{{ data.name }}</view>
            </view>
          </template>
          <template #chart="{ data }">
            <view class="stock-name flex y">
              <view>{{ data.code }}</view>
            </view>
          </template>
......

image

微信小程序解析:
image
image

HBuilderX 4.36

可以看到,解析后的插槽名变了,如何能正确渲染?

@GRCmade
Copy link
Collaborator

GRCmade commented Mar 5, 2025

hello , 你提供的这部分代码,并不是能很方便的复现,你可以提供一下一个完整的可以复现的项目吗?

@GRCmade GRCmade self-assigned this Mar 5, 2025
@c-sopoo
Copy link
Author

c-sopoo commented Mar 6, 2025

slot-demo.zip
Hi,写了个简单的demo,可以看看

@GRCmade
Copy link
Collaborator

GRCmade commented Mar 6, 2025

看你提供的代码,是默认插槽与具名插槽混用了,导致了作用域不明确,这在小程序上是有问题的,小程序上不支持这么用

@c-sopoo
Copy link
Author

c-sopoo commented Mar 6, 2025

好的,我写了两种。第一种是混了,那第二种是什么原因,第二种也是上面提到的问题,

Image

@GRCmade
Copy link
Collaborator

GRCmade commented Mar 6, 2025

好的,我写了两种。第一种是混了,那第二种是什么原因,第二种也是上面提到的问题,

Image

也是的,你第二种写法不就是把 for 循环拆出来了?代码是一样的

@c-sopoo
Copy link
Author

c-sopoo commented Mar 6, 2025

好的,我写了两种。第一种是混了,那第二种是什么原因,第二种也是上面提到的问题,
Image

也是的,你第二种写法不就是把 for 循环拆出来了?代码是一样的

逻辑是一样的,第一种把默认插槽内容去掉就正常;第二种去掉默认插槽内容还是出不来;具体表现可以看节点审查,第二种的name不匹配了;但是这两种在h5上表现一致;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants