Looking at the Vuetify example code for v-toolbar
, what is the purpose of v-slot:activator="{ on }"
? For example:
<template v-slot:activator="{ on }">
<v-toolbar-title v-on="on">
<span>All</span>
<v-icon dark>arrow_drop_down</v-icon>
</v-toolbar-title>
</template>
<script>
export default {
data: () => ({
items: [
'All', 'Family', 'Friends', 'Coworkers'
]
})
}
</script>
As far as I can see, on
is not a defined variable anywhere, so I don't see how this is working. When I try it in my project, Internet Explorer throws an error on the <template v-slot:activator="{ on }">
, but if I remove it, the page renders.
You're likely referring to this example:
The following line declares a scoped slot named
activator
, and it is provided a scope object (fromVMenu
), which contains a property namedon
:This uses destructuring syntax on the scope object, which IE does not support.
For IE, you'd have to dereference
on
from the scope object itself:But the ideal solution IMO is to use a Vue CLI generated project, which includes a Babel preset (
@vue/babel-preset-app
) to automatically include the transforms/polyfills needed for the target browsers. In this case,babel-plugin-transform-es2015-destructuring
would be automatically applied during the build.Details on the
activator
slotVMenu
allows users to specify a slotted template namedactivator
, containing component(s) that activate/open the menu upon certain events (e.g.,click
).VMenu
provides listeners for those events via an object, passed to theactivator
slot:The slot content can access
VMenu
's event listeners like this:For improved readability, the scoped data can also be destructured in the template:
The listeners from the scope object are passed to the
<button>
withv-on
's object syntax, which binds one or more event/listener pairs to the element. For this value ofon
:...the button's click handler is bound to a
VMenu
method.