Vue.js Scoped Slots & Renderless Components

  Рет қаралды 14,572

Andre Madarang

Andre Madarang

Күн бұрын

Пікірлер
@ramstein74
@ramstein74 6 жыл бұрын
The best explanation about scoped slots so far.... Thank you
@drehimself
@drehimself 6 жыл бұрын
Thanks for watching!
@SinisterSlay1
@SinisterSlay1 5 жыл бұрын
Very good explanation. But I am having trouble seeing a use case for this. Your get-json would be better served by a method or even a vuex action so you don't re-get the json every time any parent node updates. And you ended up duplicating your layout several times. Ultimately ending up with the more code then you started with. Scoped slots also means the parent must always have a layout, rather than just amending an existing layout. Is it possible to have a default layout, and a scoped slot to change the layout for those one off scenarios? I feel that would give a clear use case.
@ortzinator
@ortzinator 3 жыл бұрын
Whatever goes inside the slot tag is the default.
@SinisterSlay1
@SinisterSlay1 Жыл бұрын
Many years later, I figured out when to actually use this. When you're making a component that does nothing but fetch data of some kind from something. This let's you take your data layer out of your methods, your computeds, and Vuex (Pinia now) and use it in your template where you needed it anyways. With careful use of caching to prevent mounted events accidentally re-running your fetch calls, you can make a very template oriented data structure. So for example, you have a component that has user information in it. It has no display, using it just returns a user object. You can now place something like {{ userData.full_name }} and get nicely reusable code without having to duplicate methods and mounted and data props just to keep retrieving user data. Once I realized this use case, it revolutionized the reusability of my code. And you can still copy the data back to your methods by adding an @onload="localUserData = userData" to the component so whenever it loads, it copies the data.
@Idagudominicidoko
@Idagudominicidoko 5 жыл бұрын
I have been trying to test a component that has a child component which uses scoped slots.. Is there a way to stub or mock the data I get from the child component in order to test it against a method called with it as a parameter ??
@gknt7234
@gknt7234 4 жыл бұрын
When I want to use the component, I get an error : "TypeError: Cannot read property 'userId' of null", then it is rendered. {{ data.userId }}
@gknt7234
@gknt7234 4 жыл бұрын
Instead of null data, I did this one so there is no error now. ... setup(props, vm) { const state = reactive({ data: () => [], loading: false }) ... }
@RhyandMarketingGroup
@RhyandMarketingGroup 4 жыл бұрын
Love the work Andre! Question: Why use a scoped scope in the way you did with vs just making it an inline-template? I'm sure I'm missing a benefit to scoped slots, I just need help seeing it. Thanks! {{ message }} ---VS--- {{ message }}
@amkamn1886
@amkamn1886 4 жыл бұрын
HI can u explain this code please ? render() { return this.$scopedSlots.default({ response: this.response }) },
@burnblue
@burnblue 5 жыл бұрын
Why call the gamelist renderless if you just move the template to a render function? I thought renderless was when render = null. Maybe we could call this pass-through render or something. The start of the video implies that instead of making a separate component for grid vs vertical, the clean solution will be to move all the same markup to the parent. In the end we see that we do write new components to clean up, and the real lesson is separating data fetch (generic component) from layout (generic component) and using the parent to give those meaning. This is a valid lesson, I would have been excited to be led down that path (given a heads up) from the beginning, instead of wondering how putting all the markup in the parent is less messy. I'm being critical but this video just made something click for me so I do appreciate.
@vikasni95
@vikasni95 3 жыл бұрын
Tquu soo much sir,, very very nice and clean explanation 👌😊
@nemnoton
@nemnoton 5 жыл бұрын
Really interesting, great examples.
@drehimself
@drehimself 5 жыл бұрын
Thanks for watching!
@christostsangaris4785
@christostsangaris4785 5 жыл бұрын
Amazing content as always!
@TrayHardPlay
@TrayHardPlay 4 жыл бұрын
WAAAAIT, is it your were singing that funny song "And so you code...." like a developers remix on "Alors and danse"? PLEASE ANSWER
@marcobraun4723
@marcobraun4723 3 жыл бұрын
Hey thanks, pretty nice explaintation :)
@Martin-bm7ol
@Martin-bm7ol 5 жыл бұрын
wow,you are great! it is very useful
@evans8245
@evans8245 5 жыл бұрын
you sir, are a dirty slot ! arent ya XD
@jordiortega7687
@jordiortega7687 4 жыл бұрын
Hi Andre! I would like to have a "renderlees + functional component". Is that possible? I have try some combinations to change the render function without success. Example of non functional render: render () { return this.$scopedSlots.default({ myItem: this.items }); }, Thanks!! btw --> best explanation ever!
@elysium2013
@elysium2013 6 жыл бұрын
Cool!
@drehimself
@drehimself 6 жыл бұрын
Thanks for watching!
@7kretzsche3
@7kretzsche3 5 жыл бұрын
have u ever heard about code indentation?
@NoOorZ24
@NoOorZ24 2 жыл бұрын
I think this is a poorly chosen example. Writing all of HTML in parent component isn't really reusable. Way better solution would be to create 2 separate components and have them use the same JS file. That way HTML is separated and only 1 JS file is used. I get that you most likely just wanted to show how to use slots, but this felt like a bad example as you begun by talking about reusability and then created a component that only reuses JS, but HTML would have to be copy-pasted if same component is reused in more files
Vue.js Tips: Use Slots The Right Way // VUE.JS SLOTS TUTORIAL WITH VUE 3
11:59
Vue Slots Simplified
7:25
LearnVue
Рет қаралды 57 М.
Sigma girl VS Sigma Error girl 2  #shorts #sigma
0:27
Jin and Hattie
Рет қаралды 124 МЛН
ВЛОГ ДИАНА В ТУРЦИИ
1:31:22
Lady Diana VLOG
Рет қаралды 1,2 МЛН
Bootstrap with Vue.js
29:58
Andre Madarang
Рет қаралды 115 М.
How to build customizable and reusable Vue components by Filip Rakowski
24:18
Vue v-model in child components and defineModel
17:30
Andre Madarang
Рет қаралды 10 М.
Vuex Explained Visually by Adam Jahr
26:33
VueConf Toronto
Рет қаралды 18 М.
The Trick to Understanding Scoped Slots in Vue.js
9:59
Adam Wathan
Рет қаралды 54 М.
Vue 3 & A First Look at the Composition API
44:41
Academind
Рет қаралды 95 М.
Vuex Crash Course | State Management
1:01:19
Traversy Media
Рет қаралды 400 М.