-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(state): example of state.modified_keys usgae
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from trame.app import get_server | ||
from trame.ui.vuetify import SinglePageLayout | ||
from trame.widgets import vuetify2 as vuetify | ||
|
||
server = get_server(client_type="vue2") | ||
state, ctrl = server.state, server.controller | ||
|
||
state.field1 = 1 | ||
state.field2 = 2 | ||
state.field3 = 3 | ||
|
||
VAR_NAMES = ["field1", "field2", "field3"] | ||
|
||
|
||
@state.change(*VAR_NAMES) | ||
def change_detected(**_): | ||
print(f"Triggered because {list(state.modified_keys)} changed") | ||
for n in state.modified_keys: | ||
print(f"{n} = {state[n]}") | ||
|
||
|
||
with SinglePageLayout(server) as layout: | ||
with layout.content: | ||
with vuetify.VContainer( | ||
fluid=True, | ||
classes="d-flex justify-center align-center", | ||
style="height: 100%;", | ||
): | ||
with vuetify.VCard(style="max-width: 400px;"): | ||
vuetify.VCardTitle("VCard") | ||
with vuetify.VCardText(): | ||
vuetify.VTextField( | ||
v_model=("field1",), | ||
label="Field 1", | ||
outlined=True, | ||
) | ||
vuetify.VTextField( | ||
v_model=("field2",), | ||
label="Field 2", | ||
outlined=True, | ||
) | ||
vuetify.VTextField( | ||
v_model=("field3",), | ||
label="Field 3", | ||
outlined=True, | ||
) | ||
|
||
server.start() |