Rodja Trappe 2 роки тому
батько
коміт
90fd269c99
1 змінених файлів з 6 додано та 8 видалено
  1. 6 8
      website/reference.py

+ 6 - 8
website/reference.py

@@ -494,15 +494,13 @@ When NiceGUI is shut down or restarted, the startup tasks will be automatically
     def lifecycle_example():
     def lifecycle_example():
         from nicegui import Client
         from nicegui import Client
 
 
-        async def increment(client: Client):
-            counter.value += 1
+        def handle_connect():
+            if watch.value:
+                count.set_text(str(int(count.text or 0) + 1))
 
 
-        async def decrement(client: Client):
-            counter.value -= 1
-
-        counter = ui.number('connections', value=0).props('readonly').classes('w-24')
-        ui.on_connect(increment)
-        ui.on_disconnect(decrement)
+        watch = ui.checkbox('count new connections')
+        count = ui.label('').classes('mt-8 self-center text-5xl')
+        ui.on_connect(handle_connect)
 
 
     @example(ui.timer)
     @example(ui.timer)
     def timer_example():
     def timer_example():