Slots and :let #62
-
TLDR: Can a Vue slot yield its bindings to a .heex template via Super-contrived example here... MyCoolList.vue <template>
<ul>
<li v-for="item in items" :key="item.id">
<slot name="item" v-bind="{ item }" >
User <%= user.email %> has id <%= user.email %>
</slot>
</li>
</ul>
</template> my_cool_liveview.ex # Default slot content, no problem
<.vue v-component="MyCoolList" items={[user_1, user_2, ...]} />
# No good, because `user` is `nil` (i.e. `v-bind` didn't translate)
<.vue v-component="MyCoolList" items={[user_1, user_2, ...]}>
<:row :let={user}>
User <%= user.id %> has email <%= user.email %>
</:row>
</.vue> I see here that we're calling live_vue/lib/live_vue/slots.ex Line 33 in b46d5b3 But are slot bindings are even available in this context, to be passed to |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @blangenfeld! I don't think it's possible now. Currently slots are purely server-driven - slots are rendered on the server, and then base64 encoded and attached to the root element as live_vue/assets/js/live_vue/hooks.ts Lines 16 to 24 in b46d5b3 Then, they're passed down into Vue component as a slot. There is no mechanism of:
I don't know if it's possible, nor if it would be performant. Usually I'm just passing down array of items to Vue and let it fully handle rendering. Mixing HEEX and Vue too much doesn't work well in my experience, mostly because of component duplication. You can see more on my ElixirConfEU 2025 slides May I ask what's your use case? |
Beta Was this translation helpful? Give feedback.
Hi @blangenfeld!
I don't think it's possible now. Currently slots are purely server-driven - slots are rendered on the server, and then base64 encoded and attached to the root element as
data-slots
attribute.live_vue/assets/js/live_vue/hooks.ts
Lines 16 to 24 in b46d5b3