-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
Vue Fragments ( React Fragments ) #7606
Comments
Actually you can add slot(v-else-if="loaded") Besides, |
@jzking it emits errors Cannot use as component root element because it may contain multiple nodes. |
Duplicate of #7088 |
export default {
functional: true,
render(h, ctx) {
return ctx.children;
}
};
<template>
<table>
<thead>
<th v-for="item in columns" :key="item">
{{ item }}
</th>
</thead>
<tbody>
<template v-for="item in data">
<slot v-bind="item" />
</template>
</tbody>
</table>
</template>
<script>
// ...
</script> use it like this: <template>
<vc-table>
<!-- use it by slot-->
<vc-fragment slot-scope="it" :key="it.id">
<tr @click="handleClick($event, it.id)">点我</tr>
<tr>2</tr>
<tr>3</tr>
<tr>4</tr>
<tr>5</tr>
</vc-fragment>
</vc-table>
</template>
<script>
import Table from './Table';
import Fragment from './fragment';
export default {
name: 'vc-fragment-basic',
components: {
'vc-table': Table,
'vc-fragment': Fragment
},
methods: {
handleClick(e, id) {
alert('你点击了我');
}
}
};
</script> u can't do that like this: <template>
<vc-fragment>
<tr>1</tr>
<tr>2</tr>
<tr>3</tr>
<tr>4</tr>
<tr>5</tr>
</vc-fragment>
</template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What problem does this feature solve?
This solve the issue where multiple root components is not allowed like for instance
i'm trying to do this with slots using my own component for page loading and checking if its on loading and not loading state and checking if its valid to render the main component
So in this part of the template makes another div to just prevent the multiple root issue
so doing it like this would help
I know this thing can be done somehow on render functions
but its not vueish anymore :)
What does the proposed API look like?
so in slots
we can do
and in template syntax
Got the idea here https://reactjs.org/docs/fragments.html
The text was updated successfully, but these errors were encountered: