Slots Dom
Like thousands of slots players who use VegasSlotsOnline.com every day, you now have instant access to over 7780 free online slots that you can play right here. Our free slot games may be played in any part of the world, as long as you’re connected to the internet. Since Angular 7, we can use slots to project markup into an component's template. These slots have been introduced with Shadow DOM v1 which Angular supports since version 6.1. This article shows how to use both, Shadow DOM v1 and slots. For this, it uses a component that shows a diagram. SlotsUp is the next generation gaming website with free casino games aimed to provide the review on all online slots. Our first and foremost goal is to constantly update the slot machines demo collection, categorizing them based on casino software and features like Bonus Rounds or Free Spins. Best Online Casino DomGame 300% Welcome Bonus Monthly and Daily Promotions Slots, Video Poker, Table Games FREE or for Real Money Play on any Device and platform: PC, Mobile, Tablet, Mac, Android, iOS.
You’re browsing the documentation for v2.x and earlier. For v3.x, click here.
Basics
Vue recommends using templates to build your HTML in the vast majority of cases. There are situations however, where you really need the full programmatic power of JavaScript. That’s where you can use the render function, a closer-to-the-compiler alternative to templates.
Let’s dive into a simple example where a render
function would be practical. Say you want to generate anchored headings:
For the HTML above, you decide you want this component interface:
When you get started with a component that only generates a heading based on the level
prop, you quickly arrive at this:
That template doesn’t feel great. It’s not only verbose, but we’re duplicating <slot></slot>
for every heading level and will have to do the same when we add the anchor element.
While templates work great for most components, it’s clear that this isn’t one of them. So let’s try rewriting it with a render
function:
Much simpler! Sort of. The code is shorter, but also requires greater familiarity with Vue instance properties. In this case, you have to know that when you pass children without a v-slot
directive into a component, like the Hello world!
inside of anchored-heading
, those children are stored on the component instance at $slots.default
. If you haven’t already, it’s recommended to read through the instance properties API before diving into render functions.
Nodes, Trees, and the Virtual DOM
Before we dive into render functions, it’s important to know a little about how browsers work. Take this HTML for example:
When a browser reads this code, it builds a tree of “DOM nodes” to help it keep track of everything, just as you might build a family tree to keep track of your extended family.
The tree of DOM nodes for the HTML above looks like this:
Every element is a node. Every piece of text is a node. Even comments are nodes! A node is just a piece of the page. And as in a family tree, each node can have children (i.e. each piece can contain other pieces).
Updating all these nodes efficiently can be difficult, but thankfully, you never have to do it manually. Instead, you tell Vue what HTML you want on the page, in a template:
Or a render function:
And in both cases, Vue automatically keeps the page updated, even when blogTitle
changes.
The Virtual DOM
Vue accomplishes this by building a virtual DOM to keep track of the changes it needs to make to the real DOM. Taking a closer look at this line:
What is createElement
actually returning? It’s not exactly a real DOM element. It could perhaps more accurately be named createNodeDescription
, as it contains information describing to Vue what kind of node it should render on the page, including descriptions of any child nodes. We call this node description a “virtual node”, usually abbreviated to VNode. “Virtual DOM” is what we call the entire tree of VNodes, built by a tree of Vue components.
createElement
Arguments
The next thing you’ll have to become familiar with is how to use template features in the createElement
function. Here are the arguments that createElement
accepts:
The Data Object In-Depth
One thing to note: similar to how v-bind:class
and v-bind:style
have special treatment in templates, they have their own top-level fields in VNode data objects. This object also allows you to bind normal HTML attributes as well as DOM properties such as innerHTML
(this would replace the v-html
directive):
Complete Example
With this knowledge, we can now finish the component we started:
Constraints
VNodes Must Be Unique
All VNodes in the component tree must be unique. That means the following render function is invalid:
If you really want to duplicate the same element/component many times, you can do so with a factory function. For example, the following render function is a perfectly valid way of rendering 20 identical paragraphs:
Replacing Template Features with Plain JavaScript
v-if
and v-for
Wherever something can be easily accomplished in plain JavaScript, Vue render functions do not provide a proprietary alternative. For example, in a template using v-if
and v-for
:
This could be rewritten with JavaScript’s if
/else
and map
in a render function:
v-model
There is no direct v-model
counterpart in render functions - you will have to implement the logic yourself:
This is the cost of going lower-level, but it also gives you much more control over the interaction details compared to v-model
.
Event & Key Modifiers
For the .passive
, .capture
and .once
event modifiers, Vue offers prefixes that can be used with on
:
Modifier(s) | Prefix |
---|---|
.passive | & |
.capture | ! |
.once | ~ |
.capture.once or.once.capture | ~! |
For example:
For all other event and key modifiers, no proprietary prefix is necessary, because you can use event methods in the handler:
Modifier(s) | Equivalent in Handler |
---|---|
.stop | event.stopPropagation() |
.prevent | event.preventDefault() |
.self | if (event.target ! event.currentTarget) return |
Keys:.enter , .13 | if (event.keyCode ! 13) return (change 13 to another key code for other key modifiers) |
Modifiers Keys:.ctrl , .alt , .shift , .meta | if (!event.ctrlKey) return (change ctrlKey to altKey , shiftKey , or metaKey , respectively) |
Here’s an example with all of these modifiers used together:
Slots
You can access static slot contents as Arrays of VNodes from this.$slots
:
And access scoped slots as functions that return VNodes from this.$scopedSlots
:
To pass scoped slots to a child component using render functions, use the scopedSlots
field in VNode data:
JSX
If you’re writing a lot of render
functions, it might feel painful to write something like this:
Especially when the template version is so simple in comparison:
That’s why there’s a Babel plugin to use JSX with Vue, getting us back to a syntax that’s closer to templates:
Aliasing createElement
to h
is a common convention you’ll see in the Vue ecosystem and is actually required for JSX. Starting with version 3.4.0 of the Babel plugin for Vue, we automatically inject const h = this.$createElement
in any method and getter (not functions or arrow functions), declared in ES2015 syntax that has JSX, so you can drop the (h)
parameter. With prior versions of the plugin, your app would throw an error if h
was not available in the scope.
For more on how JSX maps to JavaScript, see the usage docs.
Functional Components
The anchored heading component we created earlier is relatively simple. It doesn’t manage any state, watch any state passed to it, and it has no lifecycle methods. Really, it’s only a function with some props.
In cases like this, we can mark components as functional
, which means that they’re stateless (no reactive data) and instanceless (no this
context). A functional component looks like this:
Note: in versions before 2.3.0, the props
option is required if you wish to accept props in a functional component. In 2.3.0+ you can omit the props
option and all attributes found on the component node will be implicitly extracted as props.
The reference will be HTMLElement when used with functional components because they’re stateless and instanceless.
In 2.5.0+, if you are using single-file components, template-based functional components can be declared with:
Everything the component needs is passed through context
, which is an object containing:
props
: An object of the provided propschildren
: An array of the VNode childrenslots
: A function returning a slots objectscopedSlots
: (2.6.0+) An object that exposes passed-in scoped slots. Also exposes normal slots as functions.data
: The entire data object, passed to the component as the 2nd argument ofcreateElement
parent
: A reference to the parent componentlisteners
: (2.3.0+) An object containing parent-registered event listeners. This is an alias todata.on
injections
: (2.3.0+) if using theinject
option, this will contain resolved injections.
After adding functional: true
, updating the render function of our anchored heading component would require adding the context
argument, updating this.$slots.default
to context.children
, then updating this.level
to context.props.level
.
Since functional components are just functions, they’re much cheaper to render.
They’re also very useful as wrapper components. For example, when you need to:
- Programmatically choose one of several other components to delegate to
- Manipulate children, props, or data before passing them on to a child component
Here’s an example of a smart-list
component that delegates to more specific components, depending on the props passed to it:
Passing Attributes and Events to Child Elements/Components
On normal components, attributes not defined as props are automatically added to the root element of the component, replacing or intelligently merging with any existing attributes of the same name.
Functional components, however, require you to explicitly define this behavior:
By passing context.data
as the second argument to createElement
, we are passing down any attributes or event listeners used on my-functional-button
. It’s so transparent, in fact, that events don’t even require the .native
modifier.
If you are using template-based functional components, you will also have to manually add attributes and listeners. Since we have access to the individual context contents, we can use data.attrs
to pass along any HTML attributes and listeners
(the alias for data.on
) to pass along any event listeners.
slots()
vs children
You may wonder why we need both slots()
and children
. Wouldn’t slots().default
be the same as children
? In some cases, yes - but what if you have a functional component with the following children?
For this component, children
will give you both paragraphs, slots().default
will give you only the second, and slots().foo
will give you only the first. Having both children
and slots()
therefore allows you to choose whether this component knows about a slot system or perhaps delegates that responsibility to another component by passing along children
.
Template Compilation
You may be interested to know that Vue’s templates actually compile to render functions. This is an implementation detail you usually don’t need to know about, but if you’d like to see how specific template features are compiled, you may find it interesting. Below is a little demo using Vue.compile
to live-compile a template string:
Free Mobile Slots Alternatives
Slots Without Shadow Dom
Our Flash powered slots unfortunately do not work on mobile devices. However, below we have a selection of of our exclusive HTML5 powered mobile friendly slots which you can play on phones and tablets. We're currently hard at work converting all our games into mobile friendly slots games and you can see our mobile slots page for all the latest!
Our Valentines Slot game is a 5 reel game with 9 paylines & a floating hearts free spins bonus feature.
Play Valentines SlotCelebrate the Year of the Monkey with this great 9 payline slot with Free Spins and a Bonus Gamble Feature!
Chinese New Year SlotOur Winter Wonderland game is a 5 reel, 20 payline slot game with two wilds and a Gamble game.
Play Winter Wonderland SlotGet 3 Bingo Bonus symbols on the reels to activate the Speed Bingo Bonus Game! This is a 30 ball version of bingo where you have to get 9 numbers daubed off your card before all 30 numbers are called.
Play Free Bingo Slots Our exclusive Cleopatra Slots Game features 2 scatter symbols, a wild symbol, Free spins feature plus a Pyramid bonus game.