Posted  by  admin

Slot Scope Props Vue

  1. Slot Scope Props Vue Set
  2. Slot-scope= Props Vuetify
  3. Slot Scope Props Vueling
  4. Vue Slot-scope Props Not Defined
  5. Slot Scope Props Vue For Sale
  6. Slot Scope Props Vue Download

Scoped slots are one of Vue's most powerful features, but it can be a bit tricky to understand how they work when first learning about them.

In this screencast (taken from my Advanced Vue Component Design course), I walk through how thinking of scoped slots as function props can make it a lot easier to wrap your head around them.

Vue template 中 slot-scope/scope 的使用. Vue template 中 slot-scope/scope 的使用在vue 2.5.0+ 中slot-scope替代了 scope template 的使用情形为,我们已经封装好一个组件,预留了插槽,使用 的插槽. 首先 我们的创建一个组件 组件很简单有一个 slot,slot有两个属性 a=123,b=msg.

  • You can tie a watcher to the slot’s scope within the component definition and emit an event whenever the data passed into the slot-scope changes, then subscribe to that event in whatever component is rendering the component with scoped slots: ScopedSlotComponent.vue.
  • It’s included in the setupScope slot。 At the same time, the two scopes can be considered to have parent-child relationship, which is used in the first code segmentcurrent-userThe module’s page or the module’s Vue scope is calledcurrent-userThe parent scope of the Vue scope of the module. Further, we can divide the goals into two.
  • The default slot scope contains the property expanded, which will be true when the collapse is expanded, or false when the collapse is collapsed. Note that the expanded scope property only works when supplying the target prop as a string, and not an array.
Vue

Learning More

Slot Scope Props Vue Set

If you enjoyed this screencast, check out Advanced Vue Component Design, a video series I'm working on that goes deep into tons of useful component design patterns.

Visit the website to learn more or subscribe below for periodic updates, more free screencasts, and a big discount when the course is released this May:

Isolation of Vue scope of components

These two pieces of code already have two different Vue scopes. One is to use thecurrent-userThe page of the module or the Vue instance and corresponding scope of the module, the other iscurrent-userThe module itself corresponds to the Vue instance and the corresponding scope.

These two scopes are isolated from each other. Without any additional settings, you cannot access each other’s Vue instances, so don’t say anythingdatamethodsThe members of such a Vue instance are all non interactive.

On this basis, when we need to achieve the goal that these two scopes can know some information about each other, we have to take some settings. It’s included in the setupScope slot。 At the same time, the two scopes can be considered to have parent-child relationship, which is used in the first code segmentcurrent-userThe module’s page or the module’s Vue scope is calledcurrent-userThe parent scope of the Vue scope of the module. Further, we can divide the goals into two categories: first, the Father knows the information of the son; second, the son knows the information of the father.

The real purpose of the scope slot is to let the parent know the information of the child

At first, I mistakenly thought that the purpose of the scope slot was to let the child know the parent’s information, so that I could never understand the scope slot. But if you take the idea that the purpose of the scope slot is to let the father know the son, you will feel that the official document is suddenly open. Official document portal.

Where does the user come from? So.

Yes, this oneuserFrom the very beginningcurrent-userIn the Vue scope within this module, the section of official documents is not intended to solve the internal problem{{user.lastName}}OfuserNeed parent pass in, but in parent{{ user.firstName }}OfuserNeed the son to tell the father!

By analyzing the mapping on this graph, we can understand why the father can know the information in the child.

First of all, when using components, the father can’t write directly that he wants to replace them as comfortably as before<slot>We need to use one first<template>

Secondly, the father must know the name of the son he wants to know. If there is only one child, the child must be called “defualt”. It doesn’t matter if it’s not written in the son, or if it’s not written in the father. That is in the picture.name='default'andv-slot:default='slotProps'Of:defualtCan be deleted.

Slot-scope= Props Vuetify

Then for the data in the child that you want to know, consider a key value for it, which isv-bind:userMediumuser, and the data value of the child corresponding to the key isv-bind:user='user'in'user'Affirmatory. This forms a key value pair of “slot prop”, or a member variable in an object containing all “slot prop”.

Slot Scope Props Vueling

And then in the corresponding<slot>Of<template>On, give a name to the reference of the object containing all the “slot prop” in the formatV-slot [: slot name] = 'what you love'Here[:slotname]How to write the first paragraph and say it out? Since it’s a name, it must be something to love, as long as it’s consistent.

At this point, the real purpose and writing of the scope slot are clear. Let’s take a look at its actual use.

Actual use of scope slots

The scope slot is used by the button of the action column in the custom column template style of the table component of the elementui

Only some codes are posted here

Vue Slot-scope Props Not Defined

The obsolete writing method used here. Paste the corresponding relationship between the obsolete writing method and the current recommended writing method
Still the same, if there’s only one<slot>It doesn’t matter whether you write or not.

Slot Scope Props Vue For Sale

In this instance of elementui, you can see its use of scope slots:scope.$indexThis explains$indexyes<el-table-column>A data within the module, afterconsole.log()In the big method test, it is found that this corresponds to the number of rows in the row where the deleted button is clicked minus one.

Slot Scope Props Vue Download

It’s reasonable to think so,<el-table-column>Data traversal in<el-table>Of:data=The bound array is continuously generated. Each time it is generated, there is a sequence number inside (that is, a child)$indexTo record ourselves is the number one. At this time, we need to use the scope slot to access this data like in the parent.