In a template – a vue_app()'s, el$ tags, a slot, a cell –
v_on(click = "n++", "keyup.enter" = "send()") gives the tag its
handlers, as @click="n++" does: Vue's inline statements, $event the
event's first argument, modifiers in the name as Vue writes them.
Arguments
- ...
In a template, handlers by event:
click = "n++". As a value ofon, one statement, unnamed.- ns
In a module, its namespace: the function
shiny::NS()gives,session$ns, or the module's id.
Details
As a value of a component's on, v_on("statement", ns = ns) is a
statement run with a module's names, as v_bind() evaluates an
expression: $vueStore.ui is vue_store(ns("ui")), $inputs.size the
module's input. Outside a module a plain string does the same:
on = list(click = "$vueStore.ui.open = true").
As in Vue, a method path ("save", "$vueStore.cart.add") or a
function expression ("(pattern, prefix) => ...") is a handler, called
with all the event's arguments; anything else is a statement, with
$event. Vue's compiler tells them apart, and so do these, by its rule.
See also
Other directives:
directives
Examples
vue_app(
"counter",
htmltools::tags$button(v_on(click = "n++"), "Clicked {{ n }} times"),
data = list(n = 0)
)
#> <div id="counter" data-shiny-vue style="display: contents">
#> <script type="text/x-template" data-shiny-vue-template><button @click="n++">Clicked {{ n }} times</button></script>
#> <script type="application/json" data-shiny-vue-options>{"options":{"data":{"n":0}},"evals":[]}</script>
#> </div>
panel_ui <- function(id) {
ns <- shiny::NS(id)
htmltools::tagList(
vue_store(ns("ui"), state = list(n = 0)),
vue_app(
ns("add"),
htmltools::tags$button("Add"),
on = list(click = v_on("$vueStore.ui.n++", ns = ns))
)
)
}