-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Props to slots #4766
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
Comments
You could write this by yourself: <ElementsList xs='1' sm='2' lg='3' passToSlot='true'>
<Grid xs='12' sm='6' lg='3'>
slot content here
</Grid>
<Grid xs='12' sm='6' lg='3'>
slot content here
</Grid>
<Grid xs='12' sm='6' lg='3'>
slot content here
</Grid> Since all the values are directly available there If you really want to have the same values while updating only at one place, you should be able to achieve this with scoped slots (https://vuejs.org/v2/guide/components.html#Scoped-Slots) or by simply referring to the As you pointed out, it should be doable with a render function too but I didn't dig into it. Since the behaviour you're asking for is an implicit version of something that can already be achieved, I doubt it makes sense to implement it |
Yep, it looks like a solution for now, though it would be nice to have something that looks simple on the front, the example you have kindly provided: <element-list :xs="xs" :sm="sm">
<template scope="props">
<grid :xs="props.xs" :sm="props.sm"></grid>
<grid :xs="props.xs" :sm="props.sm"></grid>
</template>
</element-list> The 'simple' syntax that would be (maybe), more readable <element-list :xs="xs" :sm="sm" passProps='true'>
<grid></grid>
<grid></grid>
</element-list> I actually don't know how complex it is to 'find' the children |
@dorseth we prefer the explicit way. You can always rely on the |
You can achieve what you want by using render function, and iterate through the VNodes in |
Sorry to bump it up, here is a quick and a very dirty solution without the render function of what I've been looking. Maybe it will help someone to write their own cleaner lib for that :) <template>
<Grid xs='12' :mod='wrapper'>
<Grid v-for='n in fheight' :extra='extra' >
<Grid :xs='fxs' :md='fmd' :lg='flg' v-for='a in fwidth' :extra='childExtra' :mod='same'>
<slot :name='"cell_"+n + "_" + a'>
</slot>
</Grid>
</Grid>
</Grid>
</template>
<script>
import match from 'jquery-match-height'
import Grid from './grid.vue'
export default {
props: {
width: {
default: '1'
},
height: {
default: '1'
},
xs: {
type: String
},
md: {
type: String
},
lg: {
type: String
},
elems: {
default: '1'
},
extra: {
type: String,
default: ''
},
childExtra:{
type: String,
default: ''
},
same: {
type: String,
default: ''
},
wrapper: {
type: String,
default: ''
}
},
components: {
Grid
},
created() {
if (this.xs !== '5', '7', '8', '9', '10') {
this.fxs = (12 / parseInt(this.xs)) + '';
}
if (this.md !== '5', '7', '8', '9', '10') {
this.fmd = (12 / parseInt(this.md)) + '';
}
if (this.lg !== '5', '7', '8', '9', '10') {
this.flg = (12 / parseInt(this.lg)) + '';
}
if(!this.md){
this.fmd = this.fxs;
}
if(!this.lg){
this.flg = this.fxs;
}
},
mounted(){
if (this.same.length > 1) {
$('.'+this.same).matchHeight({byRow: false});
}
},
data() {
return {
fwidth: parseInt(this.width),
fheight: parseInt(this.height),
}
}
}
</script> |
I accomplished this throught a customized context:
|
FYI: this can now be accomplished using provide / inject |
Hi, I wonder if it would be good to have something like this. (maybe it's already achievable via current Vue functional, but I didn't find it)
Imagine I have a 12 rows Grid component that has props of xs, sm,md and lg, has a single slot and
looks like this:
What I want is to have something like a modifier for the wrapped components, so it would be possible to do something like this
The ElementsList takes the props, transforms them and passes to Grid accordingly.
So after the component passes props to slot I have something like this:
The text was updated successfully, but these errors were encountered: