Passing data from a component that contains slot content to that slot content component
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
This is simpler than it sounds. I don't think I know the proper terminology to improve the title.
I want to pass data from a component that contains slot content to that slot content component.
Specifically, I have data I want to pass called tier
in Sponsors.vue
. I want to pass that data to SponsorCard.vue
.
Right now, some SponsorCard.vue
components are being send to a slot inside a SponsorCardWrapper.vue
component within my Sponsors.vue
file. I want to use tier
inside my SponsorCard.vue
component. (Specifically, I want to change the width of the image depending on the tier level of the sponsor, which I can do provided that I send the tier
prop).
Sponsors.vue
<template>
<sponsor-card-wrapper tier="gold">
<sponsor-card showSponsor="gamma"></sponsor-card>
</sponsor-card-wrapper>
</template>
SponsorCardWrapper.vue
<template>
<div class="sponsor-card-wrapper">
<h2> {{ tier }} </h2>
<layout-card-overflow :class="tier">
<slot></slot>
</layout-card-overflow>
</div>
</template>
SponsorCard.vue
<template>
<div class="sponsor">
<h3> {{ sponsor.name }} </h3>
<img :src="sponsor.image" :alt="sponsor.imageAltText" width="250px"/>
</div>
</template>
<script>
data() {
computed: {
sponsor: function() {
return this.sponsors[this.showSponsor]
}
}
}
</script>
One approach is to pass a prop even single one of my SponsorCard component directly, <sponsor-card tier="gold" showSponsor="gamma"></sponsor-card>
. But I don't want to do that because I'd like to just move a SponsorCard
component from inside one SponsorCardWrapper
to another. I also tried to create scoped slots, but I don't think I'm supposed to be using them here.
Any help would be appreciated. If there is any problems with my description or I need improvements to my terminology, let me know!
javascript html vue.js vuejs2
add a comment |
This is simpler than it sounds. I don't think I know the proper terminology to improve the title.
I want to pass data from a component that contains slot content to that slot content component.
Specifically, I have data I want to pass called tier
in Sponsors.vue
. I want to pass that data to SponsorCard.vue
.
Right now, some SponsorCard.vue
components are being send to a slot inside a SponsorCardWrapper.vue
component within my Sponsors.vue
file. I want to use tier
inside my SponsorCard.vue
component. (Specifically, I want to change the width of the image depending on the tier level of the sponsor, which I can do provided that I send the tier
prop).
Sponsors.vue
<template>
<sponsor-card-wrapper tier="gold">
<sponsor-card showSponsor="gamma"></sponsor-card>
</sponsor-card-wrapper>
</template>
SponsorCardWrapper.vue
<template>
<div class="sponsor-card-wrapper">
<h2> {{ tier }} </h2>
<layout-card-overflow :class="tier">
<slot></slot>
</layout-card-overflow>
</div>
</template>
SponsorCard.vue
<template>
<div class="sponsor">
<h3> {{ sponsor.name }} </h3>
<img :src="sponsor.image" :alt="sponsor.imageAltText" width="250px"/>
</div>
</template>
<script>
data() {
computed: {
sponsor: function() {
return this.sponsors[this.showSponsor]
}
}
}
</script>
One approach is to pass a prop even single one of my SponsorCard component directly, <sponsor-card tier="gold" showSponsor="gamma"></sponsor-card>
. But I don't want to do that because I'd like to just move a SponsorCard
component from inside one SponsorCardWrapper
to another. I also tried to create scoped slots, but I don't think I'm supposed to be using them here.
Any help would be appreciated. If there is any problems with my description or I need improvements to my terminology, let me know!
javascript html vue.js vuejs2
add a comment |
This is simpler than it sounds. I don't think I know the proper terminology to improve the title.
I want to pass data from a component that contains slot content to that slot content component.
Specifically, I have data I want to pass called tier
in Sponsors.vue
. I want to pass that data to SponsorCard.vue
.
Right now, some SponsorCard.vue
components are being send to a slot inside a SponsorCardWrapper.vue
component within my Sponsors.vue
file. I want to use tier
inside my SponsorCard.vue
component. (Specifically, I want to change the width of the image depending on the tier level of the sponsor, which I can do provided that I send the tier
prop).
Sponsors.vue
<template>
<sponsor-card-wrapper tier="gold">
<sponsor-card showSponsor="gamma"></sponsor-card>
</sponsor-card-wrapper>
</template>
SponsorCardWrapper.vue
<template>
<div class="sponsor-card-wrapper">
<h2> {{ tier }} </h2>
<layout-card-overflow :class="tier">
<slot></slot>
</layout-card-overflow>
</div>
</template>
SponsorCard.vue
<template>
<div class="sponsor">
<h3> {{ sponsor.name }} </h3>
<img :src="sponsor.image" :alt="sponsor.imageAltText" width="250px"/>
</div>
</template>
<script>
data() {
computed: {
sponsor: function() {
return this.sponsors[this.showSponsor]
}
}
}
</script>
One approach is to pass a prop even single one of my SponsorCard component directly, <sponsor-card tier="gold" showSponsor="gamma"></sponsor-card>
. But I don't want to do that because I'd like to just move a SponsorCard
component from inside one SponsorCardWrapper
to another. I also tried to create scoped slots, but I don't think I'm supposed to be using them here.
Any help would be appreciated. If there is any problems with my description or I need improvements to my terminology, let me know!
javascript html vue.js vuejs2
This is simpler than it sounds. I don't think I know the proper terminology to improve the title.
I want to pass data from a component that contains slot content to that slot content component.
Specifically, I have data I want to pass called tier
in Sponsors.vue
. I want to pass that data to SponsorCard.vue
.
Right now, some SponsorCard.vue
components are being send to a slot inside a SponsorCardWrapper.vue
component within my Sponsors.vue
file. I want to use tier
inside my SponsorCard.vue
component. (Specifically, I want to change the width of the image depending on the tier level of the sponsor, which I can do provided that I send the tier
prop).
Sponsors.vue
<template>
<sponsor-card-wrapper tier="gold">
<sponsor-card showSponsor="gamma"></sponsor-card>
</sponsor-card-wrapper>
</template>
SponsorCardWrapper.vue
<template>
<div class="sponsor-card-wrapper">
<h2> {{ tier }} </h2>
<layout-card-overflow :class="tier">
<slot></slot>
</layout-card-overflow>
</div>
</template>
SponsorCard.vue
<template>
<div class="sponsor">
<h3> {{ sponsor.name }} </h3>
<img :src="sponsor.image" :alt="sponsor.imageAltText" width="250px"/>
</div>
</template>
<script>
data() {
computed: {
sponsor: function() {
return this.sponsors[this.showSponsor]
}
}
}
</script>
One approach is to pass a prop even single one of my SponsorCard component directly, <sponsor-card tier="gold" showSponsor="gamma"></sponsor-card>
. But I don't want to do that because I'd like to just move a SponsorCard
component from inside one SponsorCardWrapper
to another. I also tried to create scoped slots, but I don't think I'm supposed to be using them here.
Any help would be appreciated. If there is any problems with my description or I need improvements to my terminology, let me know!
javascript html vue.js vuejs2
javascript html vue.js vuejs2
asked Nov 21 '18 at 23:08
EdwinEdwin
118110
118110
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I think you should use Scoped Slots.
https://vuejs.org/v2/guide/components-slots.html#Scoped-Slots
https://medium.com/binarcode/understanding-scoped-slots-in-vue-js-db5315a42391
Something like this:
Sponsors.vue
<template>
<sponsor-card-wrapper>
<sponsor-card
slot-scope="{ tier }"
:tier="tier"
></sponsor-card>
</sponsor-card-wrapper>
</template>
SponsorCardWrapper.vue
<template>
<div>
<h2>title</h2>
<layout-card-overflow>
<slot
v-bind:tier="tier"
></slot>
</layout-card-overflow>
</div>
</template>
<script>
export default {
props: ['tier']
}
</script>
SponsorCard.vue
<template>
<div>
<h3>{{ tier }}</h3>
</div>
</template>
<script>
export default {
props: ['tier']
}
</script>
This is very useful for lists rendering.
In your case, why don't you just do:
<template>
<sponsor-card-wrapper tier="gold">
<sponsor-card showSponsor="gamma" tier="gold"></sponsor-card>
</sponsor-card-wrapper>
</template>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421706%2fpassing-data-from-a-component-that-contains-slot-content-to-that-slot-content-co%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think you should use Scoped Slots.
https://vuejs.org/v2/guide/components-slots.html#Scoped-Slots
https://medium.com/binarcode/understanding-scoped-slots-in-vue-js-db5315a42391
Something like this:
Sponsors.vue
<template>
<sponsor-card-wrapper>
<sponsor-card
slot-scope="{ tier }"
:tier="tier"
></sponsor-card>
</sponsor-card-wrapper>
</template>
SponsorCardWrapper.vue
<template>
<div>
<h2>title</h2>
<layout-card-overflow>
<slot
v-bind:tier="tier"
></slot>
</layout-card-overflow>
</div>
</template>
<script>
export default {
props: ['tier']
}
</script>
SponsorCard.vue
<template>
<div>
<h3>{{ tier }}</h3>
</div>
</template>
<script>
export default {
props: ['tier']
}
</script>
This is very useful for lists rendering.
In your case, why don't you just do:
<template>
<sponsor-card-wrapper tier="gold">
<sponsor-card showSponsor="gamma" tier="gold"></sponsor-card>
</sponsor-card-wrapper>
</template>
add a comment |
I think you should use Scoped Slots.
https://vuejs.org/v2/guide/components-slots.html#Scoped-Slots
https://medium.com/binarcode/understanding-scoped-slots-in-vue-js-db5315a42391
Something like this:
Sponsors.vue
<template>
<sponsor-card-wrapper>
<sponsor-card
slot-scope="{ tier }"
:tier="tier"
></sponsor-card>
</sponsor-card-wrapper>
</template>
SponsorCardWrapper.vue
<template>
<div>
<h2>title</h2>
<layout-card-overflow>
<slot
v-bind:tier="tier"
></slot>
</layout-card-overflow>
</div>
</template>
<script>
export default {
props: ['tier']
}
</script>
SponsorCard.vue
<template>
<div>
<h3>{{ tier }}</h3>
</div>
</template>
<script>
export default {
props: ['tier']
}
</script>
This is very useful for lists rendering.
In your case, why don't you just do:
<template>
<sponsor-card-wrapper tier="gold">
<sponsor-card showSponsor="gamma" tier="gold"></sponsor-card>
</sponsor-card-wrapper>
</template>
add a comment |
I think you should use Scoped Slots.
https://vuejs.org/v2/guide/components-slots.html#Scoped-Slots
https://medium.com/binarcode/understanding-scoped-slots-in-vue-js-db5315a42391
Something like this:
Sponsors.vue
<template>
<sponsor-card-wrapper>
<sponsor-card
slot-scope="{ tier }"
:tier="tier"
></sponsor-card>
</sponsor-card-wrapper>
</template>
SponsorCardWrapper.vue
<template>
<div>
<h2>title</h2>
<layout-card-overflow>
<slot
v-bind:tier="tier"
></slot>
</layout-card-overflow>
</div>
</template>
<script>
export default {
props: ['tier']
}
</script>
SponsorCard.vue
<template>
<div>
<h3>{{ tier }}</h3>
</div>
</template>
<script>
export default {
props: ['tier']
}
</script>
This is very useful for lists rendering.
In your case, why don't you just do:
<template>
<sponsor-card-wrapper tier="gold">
<sponsor-card showSponsor="gamma" tier="gold"></sponsor-card>
</sponsor-card-wrapper>
</template>
I think you should use Scoped Slots.
https://vuejs.org/v2/guide/components-slots.html#Scoped-Slots
https://medium.com/binarcode/understanding-scoped-slots-in-vue-js-db5315a42391
Something like this:
Sponsors.vue
<template>
<sponsor-card-wrapper>
<sponsor-card
slot-scope="{ tier }"
:tier="tier"
></sponsor-card>
</sponsor-card-wrapper>
</template>
SponsorCardWrapper.vue
<template>
<div>
<h2>title</h2>
<layout-card-overflow>
<slot
v-bind:tier="tier"
></slot>
</layout-card-overflow>
</div>
</template>
<script>
export default {
props: ['tier']
}
</script>
SponsorCard.vue
<template>
<div>
<h3>{{ tier }}</h3>
</div>
</template>
<script>
export default {
props: ['tier']
}
</script>
This is very useful for lists rendering.
In your case, why don't you just do:
<template>
<sponsor-card-wrapper tier="gold">
<sponsor-card showSponsor="gamma" tier="gold"></sponsor-card>
</sponsor-card-wrapper>
</template>
answered Nov 22 '18 at 1:07
BlitzBlitz
11115
11115
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421706%2fpassing-data-from-a-component-that-contains-slot-content-to-that-slot-content-co%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown