Slots Vue 3
[Vue] 3. Calculate attributes, slots and custom events
If a slot is defined without a name attribute then any content which is placed within component tags not specifying a slot attribute will be placed into that slot. See the multi insertion example on the Vue.js official docs. Vue 3 tutorial Learning Vue 3. As the third version will have the same API, it should be relatively easy to learn it, if you're already familiar with previous versions. You'll find the Vue 3 step-by-step tutorial under this link when it's out. You can also join the newsletter above and we'll notify you when documentation and tutorials for Vue 3.
Blackjack online, online roulette, online Slots Vue 3 craps, slots online, baccarat online 3 card poker, pai gow poker, and Caribbean stud poker are some of the best table games to play. 3 Practice strategies before playing for real money.
1, Calculate properties
When we need to execute a function with high cost, such as traversing a super long array, if we use the methods in Vue to execute this method many times, it must be very expensive! Vue provides us with calculation properties to keep the results of our functions in the cache until the data changes. This greatly reduces the system overhead.
We use the computed tag in vue to define the calculated properties, which is very similar to methods.
At this point, we display the current timestamp on the page.
But we'll use the following getNowTime2 in the browser after a while
If we define a message in getNowTime2, and then modify the message in the browser, then the getNowTime2 will execute again and update the relevant value
2, Slot
Vue implements an API for content distribution, which was inspired by Draft Web Components specification , using the < slot > element as an exit to host the distribution.
What is a slot like? A reusable library in java? Or a reusable method, you can give it space first, and then assign the value to it.
For example, let's define a component and add a slot to the component
Then we'll try
Insert a line into zhanassi
Try it and find it can!
But if you remove the slot label, jjnb! It won't show.
Vue Named Slots
in other words:
If the template of < zhanassi > does not contain a < slot > element, anything between the start tag and the end tag of the component is discarded.
So it's equivalent to occupying a place.
You can also put html tags or other components in it.
ok, can we dynamically bind slots here?
Of course!
Here we still create two new component s, which define some parameters respectively
Here we modify the slot so that the name after the slot is the name of the two new components
Vue Slot Example
Then we define the data in the vue object
Then the code in html needs to be modified a little
Here, we add the slot attribute to the tag, and the attribute value is the value of your component. Then, we use the v:bind command to bind the attributes in the component with those in our vue object
Last run!
3, Custom events
We added something in the previous slot example.
First, we define a button in the template of the liebiao component to delete the related elements. Then we define an index attribute in the liebiao component to record the subscript position in the array. Then define an empty remove method and button to bind the event. Here, @ click is the abbreviation of v-on:click, which is used to bind the click event of a button with the remove method.
Here we want to make a data binding with the front-end code, and use v:bind to bind the item to the actual array item
Binding completed! no problem!
At this time, we define a method in the vue object dirty to delete the relevant elements in the array
Test it through the browser console:
Found deleted successfully ha!
But how can we bind the function in the vue object with the click event of the delete button in the component?
First, we need to bind events in the front-end html through v-on
It's done when it's tied, huh? absolutely wrong! We also need to define custom methods in the remove method in the component.
The first parameter here is the method name within the component, and the second is the parameter to be passed
ok! Let's try this time!
Can be deleted normally!
demo complete code: