ex4nicegui 0.6.8__py3-none-any.whl → 0.7.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. ex4nicegui/__init__.py +2 -0
  2. ex4nicegui/bi/dataSourceFacade.py +20 -20
  3. ex4nicegui/bi/index.py +20 -23
  4. ex4nicegui/helper/client_instance_locker.py +4 -4
  5. ex4nicegui/reactive/EChartsComponent/ECharts.py +9 -8
  6. ex4nicegui/reactive/__init__.py +12 -0
  7. ex4nicegui/reactive/base.py +433 -0
  8. ex4nicegui/reactive/deferredTask.py +3 -2
  9. ex4nicegui/reactive/mixins/backgroundColor.py +41 -0
  10. ex4nicegui/reactive/mixins/disableable.py +44 -0
  11. ex4nicegui/reactive/mixins/textColor.py +66 -0
  12. ex4nicegui/reactive/officials/aggrid.py +5 -5
  13. ex4nicegui/reactive/officials/base.py +4 -453
  14. ex4nicegui/reactive/officials/button.py +43 -10
  15. ex4nicegui/reactive/officials/checkbox.py +5 -5
  16. ex4nicegui/reactive/officials/chip.py +102 -0
  17. ex4nicegui/reactive/officials/circular_progress.py +9 -7
  18. ex4nicegui/reactive/officials/color_picker.py +7 -7
  19. ex4nicegui/reactive/officials/column.py +5 -5
  20. ex4nicegui/reactive/officials/date.py +5 -5
  21. ex4nicegui/reactive/officials/dialog.py +49 -0
  22. ex4nicegui/reactive/officials/echarts.py +49 -51
  23. ex4nicegui/reactive/officials/expansion.py +5 -5
  24. ex4nicegui/reactive/officials/grid.py +3 -2
  25. ex4nicegui/reactive/officials/icon.py +8 -11
  26. ex4nicegui/reactive/officials/image.py +5 -5
  27. ex4nicegui/reactive/officials/input.py +8 -8
  28. ex4nicegui/reactive/officials/knob.py +9 -5
  29. ex4nicegui/reactive/officials/label.py +8 -15
  30. ex4nicegui/reactive/officials/linear_progress.py +8 -11
  31. ex4nicegui/reactive/officials/number.py +9 -9
  32. ex4nicegui/reactive/officials/radio.py +8 -8
  33. ex4nicegui/reactive/officials/row.py +5 -5
  34. ex4nicegui/reactive/officials/select.py +9 -8
  35. ex4nicegui/reactive/officials/slider.py +6 -6
  36. ex4nicegui/reactive/officials/switch.py +5 -5
  37. ex4nicegui/reactive/officials/tab.py +0 -12
  38. ex4nicegui/reactive/officials/tab_panels.py +113 -7
  39. ex4nicegui/reactive/officials/table.py +13 -13
  40. ex4nicegui/reactive/officials/tabs.py +5 -5
  41. ex4nicegui/reactive/officials/textarea.py +5 -5
  42. ex4nicegui/reactive/officials/tooltip.py +40 -0
  43. ex4nicegui/reactive/q_pagination.py +5 -5
  44. ex4nicegui/reactive/scopedStyle.py +4 -1
  45. ex4nicegui/reactive/systems/color_system.py +132 -0
  46. ex4nicegui/reactive/vfor.js +14 -4
  47. ex4nicegui/reactive/vfor.py +128 -58
  48. ex4nicegui/reactive/view_model.py +160 -0
  49. ex4nicegui/reactive/vmodel.py +42 -12
  50. ex4nicegui/utils/apiEffect.py +5 -1
  51. ex4nicegui/utils/effect.py +3 -2
  52. ex4nicegui/utils/scheduler.py +20 -4
  53. ex4nicegui/utils/signals.py +23 -21
  54. {ex4nicegui-0.6.8.dist-info → ex4nicegui-0.7.0.dist-info}/METADATA +247 -48
  55. {ex4nicegui-0.6.8.dist-info → ex4nicegui-0.7.0.dist-info}/RECORD +57 -50
  56. ex4nicegui/reactive/services/color_service.py +0 -56
  57. {ex4nicegui-0.6.8.dist-info → ex4nicegui-0.7.0.dist-info}/LICENSE +0 -0
  58. {ex4nicegui-0.6.8.dist-info → ex4nicegui-0.7.0.dist-info}/WHEEL +0 -0
@@ -1,5 +1,6 @@
1
1
  import signe
2
2
  from signe.core.scope import Scope
3
+ from signe.core.consts import EffectState
3
4
  from typing import (
4
5
  TypeVar,
5
6
  overload,
@@ -88,7 +89,10 @@ def ui_effect(
88
89
  **kws,
89
90
  scope=scope or _CLIENT_SCOPE_MANAGER.get_current_scope(),
90
91
  )
91
- res.update()
92
+
93
+ res.trigger(EffectState.NEED_UPDATE)
94
+ scheduler.run()
95
+ # res.update()
92
96
 
93
97
  return res
94
98
 
@@ -1,4 +1,5 @@
1
1
  import signe
2
+ from signe.core.consts import EffectState
2
3
  from typing import (
3
4
  TypeVar,
4
5
  overload,
@@ -6,7 +7,6 @@ from typing import (
6
7
  Callable,
7
8
  Union,
8
9
  )
9
-
10
10
  from .scheduler import get_uiScheduler
11
11
  from .clientScope import _CLIENT_SCOPE_MANAGER
12
12
 
@@ -81,7 +81,8 @@ def effect(
81
81
  scope=_CLIENT_SCOPE_MANAGER.get_current_scope(),
82
82
  )
83
83
 
84
- res.update()
84
+ res.trigger(EffectState.NEED_UPDATE)
85
+ scheduler.run()
85
86
 
86
87
  return res
87
88
 
@@ -1,15 +1,13 @@
1
1
  from collections import deque
2
2
  import signe
3
- from typing import (
4
- TypeVar,
5
- Callable,
6
- )
3
+ from typing import TypeVar, Callable, Literal
7
4
  from functools import lru_cache
8
5
 
9
6
 
10
7
  T = TypeVar("T")
11
8
 
12
9
  T_JOB_FN = Callable[[], None]
10
+ T_JOB_TYPE = Literal["pre", "post"]
13
11
 
14
12
 
15
13
  class UiScheduler(signe.ExecutionScheduler):
@@ -18,6 +16,7 @@ class UiScheduler(signe.ExecutionScheduler):
18
16
 
19
17
  self._pre_deque: deque[T_JOB_FN] = deque()
20
18
  self._post_deque: deque[T_JOB_FN] = deque()
19
+ self._next_tick_deque: deque[T_JOB_FN] = deque()
21
20
 
22
21
  def pre_job(self, job: T_JOB_FN):
23
22
  self._pre_deque.appendleft(job)
@@ -25,6 +24,9 @@ class UiScheduler(signe.ExecutionScheduler):
25
24
  def post_job(self, job: T_JOB_FN):
26
25
  self._post_deque.appendleft(job)
27
26
 
27
+ def next_tick_job(self, job: T_JOB_FN):
28
+ self._next_tick_deque.appendleft(job)
29
+
28
30
  def run(self):
29
31
  while self._scheduler_fns:
30
32
  super().run()
@@ -33,6 +35,7 @@ class UiScheduler(signe.ExecutionScheduler):
33
35
  try:
34
36
  self.run_pre_deque()
35
37
  self.run_post_deque()
38
+ self.run_next_tick_deque()
36
39
  pass
37
40
  except Exception as e:
38
41
  raise e
@@ -47,7 +50,20 @@ class UiScheduler(signe.ExecutionScheduler):
47
50
  while self._post_deque:
48
51
  self._post_deque.pop()()
49
52
 
53
+ def run_next_tick_deque(self):
54
+ while self._next_tick_deque:
55
+ self._next_tick_deque.pop()()
56
+
50
57
 
51
58
  @lru_cache(maxsize=1)
52
59
  def get_uiScheduler():
53
60
  return UiScheduler()
61
+
62
+
63
+ def next_tick(job: T_JOB_FN):
64
+ """Schedule a job to run on the next tick of the event loop.
65
+
66
+ Args:
67
+ job (T_JOB_FN): The job to run on the next tick.
68
+ """
69
+ get_uiScheduler().next_tick_job(job)
@@ -54,11 +54,12 @@ def to_value(obj: Union[_TMaybeRef[T], RefWrapper]) -> T:
54
54
  obj (Union[_TMaybeRef[T], RefWrapper]): A getter function, an existing ref, or a non-function value.
55
55
 
56
56
  ## Example
57
- ```python
58
- to_value(1) # 1
59
- to_value(lambda: 1) # 1
60
- to_value(to_ref(1)) # 1
61
- ```
57
+
58
+ .. code-block:: python
59
+ to_value(1) # 1
60
+ to_value(lambda: 1) # 1
61
+ to_value(to_ref(1)) # 1
62
+
62
63
  """
63
64
  if is_ref(obj):
64
65
  return obj.value # type: ignore
@@ -239,26 +240,27 @@ def event_batch(event_fn: Callable[..., None]):
239
240
  Args:
240
241
  event_fn (Callable[..., None]): event callback
241
242
 
242
- @Example
243
- ```python
244
- from nicegui import ui
245
- from ex4nicegui import on, to_ref, effect, ref_computed, batch
243
+ ## Example
244
+
245
+ .. code-block:: python
246
+ from nicegui import ui
247
+ from ex4nicegui import on, to_ref, effect, ref_computed, batch
248
+
249
+ a = to_ref(0)
250
+ b = to_ref(0)
251
+ text = ref_computed(lambda: f"a={a.value};b={b.value}")
246
252
 
247
- a = to_ref(0)
248
- b = to_ref(0)
249
- text = ref_computed(lambda: f"a={a.value};b={b.value}")
253
+ @on([a, b, text])
254
+ def when_vars_changed():
255
+ ui.notify(f"a:{a.value};b:{b.value};text={text.value}")
250
256
 
251
- @on([a, b, text])
252
- def when_vars_changed():
253
- ui.notify(f"a:{a.value};b:{b.value};text={text.value}")
257
+ @event_batch
258
+ def when_click():
259
+ a.value += 1
260
+ b.value += 1
254
261
 
255
- @event_batch
256
- def when_click():
257
- a.value += 1
258
- b.value += 1
262
+ ui.button("change all values", on_click=when_click)
259
263
 
260
- ui.button("change all values", on_click=when_click)
261
- ```
262
264
  """
263
265
 
264
266
  def wrap(*args, **kwargs):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ex4nicegui
3
- Version: 0.6.8
3
+ Version: 0.7.0
4
4
  Summary: Extension library based on nicegui, providing data responsive,BI functionality modules
5
5
  Home-page: https://github.com/CrystalWindSnake/ex4nicegui
6
6
  License: MIT
@@ -17,13 +17,17 @@ Classifier: Programming Language :: Python :: 3.11
17
17
  Classifier: Programming Language :: Python :: 3.12
18
18
  Requires-Dist: executing (>=2.0.1,<3.0.0)
19
19
  Requires-Dist: nicegui (>=1.4.25,<2.0.0)
20
- Requires-Dist: signe (>=0.4.14,<0.5.0)
20
+ Requires-Dist: signe (>=0.4.20,<0.5.0)
21
21
  Project-URL: Repository, https://github.com/CrystalWindSnake/ex4nicegui
22
22
  Description-Content-Type: text/markdown
23
23
 
24
24
  # ex4nicegui
25
- [ENGLISH README](./README.en.md)
26
25
 
26
+ <div align="center">
27
+
28
+ 简体中文| [English](./README.en.md)
29
+
30
+ </div>
27
31
 
28
32
  - [教程](#教程)
29
33
  - [安装](#-安装)
@@ -191,6 +195,154 @@ ui.run()
191
195
  ---
192
196
 
193
197
 
198
+
199
+ ## ViewModel
200
+ 在 `v0.7.0` 版本中,引入 `ViewModel` 类,用于管理一组响应式数据。
201
+
202
+ 下面是一个简单的计算器示例:
203
+
204
+ 1. 当用户修改数值输入框或符号选择框,右侧会自动显示计算结果
205
+ 2. 当结果小于 0 时,结果显示为红色,否则为黑色
206
+
207
+ ```python
208
+ from ex4nicegui import rxui
209
+
210
+ class Calculator(rxui.ViewModel):
211
+ num1 = rxui.var(0)
212
+ sign = rxui.var("+")
213
+ num2 = rxui.var(0)
214
+
215
+ def result(self):
216
+ # 当 num1,sign,num2 任意一个值发生变化时,result 也会重新计算
217
+ return eval(f"{self.num1.value}{self.sign.value}{self.num2.value}")
218
+
219
+ # 每个对象拥有独立的数据
220
+ calc = Calculator()
221
+
222
+ with ui.row(align_items="center"):
223
+ rxui.number(value=calc.num1, label="Number 1")
224
+ rxui.select(value=calc.sign, options=["+", "-", "*", "/"], label="Sign")
225
+ rxui.number(value=calc.num2, label="Number 2")
226
+ ui.label("=")
227
+ rxui.label(calc.result).bind_color(
228
+ lambda: "red" if calc.result() < 0 else "black"
229
+ )
230
+
231
+ ```
232
+
233
+ ### cached_var
234
+
235
+ 上面的示例中,由于使用了两次 `calc.result` 。因此,每当 `num1`, `sign`, `num2` 任意一个值发生变化时,`result` 都会执行2次。
236
+
237
+ 实际上,第二次的计算是多余的。我们可以通过添加 `rxui.cached_var` 装饰器,避免多余的计算。
238
+
239
+ ```python
240
+ class Calculator(rxui.ViewModel):
241
+ ...
242
+
243
+ @rxui.cached_var
244
+ def result(self):
245
+ return eval(f"{self.num1.value}{self.sign.value}{self.num2.value}")
246
+
247
+ ...
248
+ ```
249
+
250
+ ---
251
+
252
+ ### 使用列表
253
+
254
+ 当数据为可变对象时,比如列表,字典等,需要提供工厂函数传给 `rxui.var`
255
+
256
+
257
+ ```python
258
+ class Home(rxui.ViewModel):
259
+ persons= rxui.var(lambda: [])
260
+
261
+ ```
262
+
263
+ 下面的示例,每个 person 使用卡片展示。最上方显示所有人的平均年龄。当个人年龄大于平均年龄,卡片外边框将变为红色。
264
+ 通过 `number` 组件修改年龄,一切都会自动更新。
265
+
266
+ ```python
267
+ from ex4nicegui import rxui, Ref
268
+ from itertools import count
269
+
270
+ id_generator = count()
271
+
272
+ class Person(rxui.ViewModel):
273
+ name = rxui.var("")
274
+ age = rxui.var(0)
275
+
276
+ def __init__(self, name: str = "", age: int = 0):
277
+ super().__init__()
278
+ self.name.value = name
279
+ self.age.value = age
280
+ self.id = next(id_generator)
281
+
282
+
283
+ class Home(rxui.ViewModel):
284
+ persons: Ref[List[Person]] = rxui.var(lambda: [])
285
+
286
+ def avg_age(self) -> float:
287
+ if len(self.persons.value) == 0:
288
+ return 0
289
+
290
+ return sum(p.age.value for p in self.persons.value) / len(self.persons.value)
291
+
292
+ def sample_data(self):
293
+ self.persons.value = [
294
+ Person("alice", 25),
295
+ Person("bob", 30),
296
+ Person("charlie", 31),
297
+ Person("dave", 22),
298
+ Person("eve", 26),
299
+ Person("frank", 29),
300
+ ]
301
+
302
+ home = Home()
303
+ home.sample_data()
304
+
305
+ rxui.label(lambda: f"平均年龄: {home.avg_age()}")
306
+
307
+
308
+ with ui.row():
309
+
310
+ @rxui.vfor(home.persons, key="id")
311
+ def _(store: rxui.VforStore[Person]):
312
+ person = store.get_item()
313
+ with rxui.card().classes("outline").bind_classes(
314
+ {
315
+ "outline-red-500": lambda: person.age.value > home.avg_age(),
316
+ }
317
+ ):
318
+ rxui.input(value=person.name, placeholder="名字")
319
+ rxui.number(value=person.age, min=1, max=100, step=1, placeholder="年龄")
320
+
321
+ ```
322
+
323
+ 如果你觉得 `rxui.vfor` 代码过于复杂,可以使用 `effect_refreshable` 装饰器代替。
324
+
325
+ ```python
326
+ from ex4nicegui import rxui, Ref,effect_refreshable
327
+ ...
328
+
329
+ # 明确指定监控 home.persons 变化,可以避免意味刷新
330
+ @effect_refreshable.on(home.persons)
331
+ def _():
332
+
333
+ for person in home.persons.value:
334
+ ...
335
+ rxui.number(value=person.age, min=1, max=100, step=1, placeholder="年龄")
336
+ ...
337
+ ```
338
+
339
+ 需要注意到,每当 `home.persons` 列表变化时(比如新增或删除元素),`effect_refreshable` 装饰的函数都会重新执行。意味着所有元素都会重新创建。
340
+
341
+
342
+ 更多复杂的应用,可以查看 [examples](./examples)
343
+
344
+ ---
345
+
194
346
  ## 响应式
195
347
 
196
348
  ```python
@@ -331,15 +483,14 @@ ui.button("change", on_click=change_value)
331
483
 
332
484
  > `ref_computed` 是只读的 `to_ref`
333
485
 
334
-
335
- 如果你更喜欢通过类组织代码,`ref_computed` 同样支持作用到实例方法上
486
+ 从 `v0.7.0` 版本开始,不建议使用 `ref_computed` 应用实例方法。你可以使用 `rxui.ViewModel`,并使用 `rxui.cached_var` 装饰器
336
487
 
337
488
  ```python
338
- class MyState:
489
+ class MyState(rxui.ViewModel):
339
490
  def __init__(self) -> None:
340
491
  self.r_text = to_ref("")
341
492
 
342
- @ref_computed
493
+ @rxui.cached_var
343
494
  def post_text(self):
344
495
  return self.r_text.value + "post"
345
496
 
@@ -494,70 +645,90 @@ rxui.input(value=data.value["a"])
494
645
  rxui.input(value=lambda: data.value["a"])
495
646
 
496
647
  # 要使用 vmodel 才能双向绑定
497
- rxui.input(value=rxui.vmodel(data.value["a"]))
648
+ rxui.input(value=rxui.vmodel(data, "a"))
649
+
650
+ # 也可以直接使用,但不推荐
651
+ rxui.input(value=rxui.vmodel(data.value['a']))
652
+
498
653
  ```
499
654
 
500
- - 第一个输入框将完全失去响应性,因为代码等价于直接传入一个数值`1`
655
+ - 第一个输入框将完全失去响应性,因为代码等价于 `rxui.input(value=1)`
501
656
  - 第二个输入框由于使用函数,将得到读取响应性(第三个输入框输入值,将得到同步)
502
657
  - 第三个输入框,使用 `rxui.vmodel` 包裹,即可实现双向绑定
503
658
 
504
- 多数在配合 `vfor` 时使用 `vmodel`,可参考 [todo list 案例](./examples/todomvc/)
659
+ > 如果使用 `rxui.ViewModel` ,你可能不需要使用 `vmodel`
505
660
 
661
+ 可参考 [todo list 案例](./examples/todomvc/)
662
+
663
+ ---
506
664
 
507
665
  ### vfor
508
- 基于列表响应式数据,渲染列表组件。每项组件按需更新。数据项支持字典或任意类型对象
666
+ 基于列表响应式数据,渲染列表组件。每项组件按需更新。数据项支持字典或任意类型对象。
667
+
668
+ 从 `v0.7.0` 版本开始,建议配合 `rxui.ViewModel` 使用。与使用 `effect_refreshable` 装饰器不同,`vfor` 不会重新创建所有的元素,而是更新已存在的元素。
669
+
670
+ 下面是卡片排序例子,卡片总是按年龄排序。当你修改某个卡片中的年龄数据时,卡片会实时调整顺序。但是,光标焦点不会离开输入框。
671
+
509
672
 
510
673
  ```python
674
+ from typing import List
511
675
  from nicegui import ui
512
- from ex4nicegui.reactive import rxui
513
- from ex4nicegui import deep_ref, ref_computed
514
- from typing import Dict
515
-
516
- # refs
517
- items = deep_ref(
518
- [
519
- {"id": 1, "message": "foo", "done": False},
520
- {"id": 2, "message": "bar", "done": True},
521
- ]
522
- )
676
+ from ex4nicegui import rxui, deep_ref as ref, Ref
523
677
 
524
- # ref_computeds
525
- @ref_computed
526
- def done_count_info():
527
- return f"done count:{sum(item['done'] for item in items.value)}"
528
678
 
529
- # method
530
- def check():
531
- for item in items.value:
532
- item["done"] = not item["done"]
679
+ class Person(rxui.ViewModel):
680
+ def __init__(self, name: str, age: int) -> None:
681
+ self.name = name
682
+ self.age = ref(age)
683
+
684
+
685
+ class MyApp(rxui.ViewModel):
686
+ persons: Ref[List[Person]] = rxui.var(lambda: [])
687
+ order = rxui.var("asc")
688
+
689
+ def sort_by_age(self):
690
+ return sorted(
691
+ self.persons.value,
692
+ key=lambda p: p.age.value,
693
+ reverse=self.order.value == "desc",
694
+ )
695
+
696
+ @staticmethod
697
+ def create():
698
+ persons = [
699
+ Person(name="Alice", age=25),
700
+ Person(name="Bob", age=30),
701
+ Person(name="Charlie", age=20),
702
+ Person(name="Dave", age=35),
703
+ Person(name="Eve", age=28),
704
+ ]
705
+ app = MyApp()
706
+ app.persons.value = persons
707
+ return app
533
708
 
534
709
 
535
710
  # ui
536
- rxui.label(done_count_info)
537
- ui.button("check", on_click=check)
711
+ app = MyApp.create()
538
712
 
713
+ with rxui.tabs(app.order):
714
+ rxui.tab("asc", "Ascending")
715
+ rxui.tab("desc", "Descending")
539
716
 
540
- @rxui.vfor(items,key='id')
541
- def _(store: rxui.VforStore[Dict]):
542
- # 函数中构建每一行数据的界面
543
- item = store.get() # 通过 store.get 获取对应行的响应式对象(相当于每行的数据 to_ref(...))
544
- mes = rxui.vmodel(item.value['message']) # 复杂结构默认没有双向绑定,需要使用 `vmodel`
545
717
 
546
- # 输入框输入内容,可以看到单选框的标题同步变化
547
- with ui.card():
548
- with ui.row():
549
- rxui.input(value=mes)
550
- rxui.label(lambda: f"{mes.value=!s}")
551
- rxui.checkbox(text=mes, value=rxui.vmodel(item.value['done']))
718
+ @rxui.vfor(app.sort_by_age, key="name")
719
+ def each_person(s: rxui.VforStore[Person]):
720
+ person = s.get_item()
721
+
722
+ with ui.card(), ui.row(align_items="center"):
723
+ rxui.label(person.name)
724
+ rxui.number(value=person.age, step=1, min=0, max=100)
552
725
 
553
726
  ```
554
727
 
555
728
  - `rxui.vfor` 装饰器到自定义函数
556
- - 第一个参数传入响应式列表。列表中每一项可以是字典或其他对象(`dataclasses` 等等)
557
- - 第二个参数 `key`: 为了可以跟踪每个节点的标识,从而重用和重新排序现有的元素,你可以为每个元素对应的块提供一个唯一的 key 。默认情况使用列表元素索引。
558
- - 自定义函数带有一个参数。通过 `store.get` 可以获取当前行的响应式对象
559
-
560
- > vfor 渲染的项目,只有在新增数据时,才会创建
729
+ - 第一个参数传入响应式列表。注意,无须调用 `app.sort_by_age`
730
+ - 第二个参数 `key`: 为了可以跟踪每个节点的标识,从而重用和重新排序现有的元素,你可以为每个元素对应的块提供一个唯一的 key 。默认情况使用列表元素索引。例子中假定每个人的名字唯一。
731
+ - 自定义函数带有一个参数。通过 `store.get_item` 可以获取当前行的对象。由于 Person 本身继承自 `rxui.ViewModel`,所以它的各项属性可以直接绑定到组件。
561
732
 
562
733
 
563
734
  ---
@@ -890,6 +1061,34 @@ rxui.label(lambda: f"当前 tab 为:{current_tab.value}")
890
1061
  ```
891
1062
  ---
892
1063
 
1064
+ ### lazy_tab_panels
1065
+
1066
+ 懒加载模式下,只有当前激活的 tab 才会渲染。
1067
+ ```python
1068
+ from ex4nicegui import to_ref, rxui, on, deep_ref
1069
+
1070
+ current_tab = to_ref("t1")
1071
+
1072
+ with rxui.tabs(current_tab):
1073
+ ui.tab("t1")
1074
+ ui.tab("t2")
1075
+
1076
+ with rxui.lazy_tab_panels(current_tab) as panels:
1077
+
1078
+ @panels.add_tab_panel("t1")
1079
+ def _():
1080
+ ui.notify("Hello from t1")
1081
+
1082
+ @panels.add_tab_panel("t2")
1083
+ def _():
1084
+ ui.notify("Hello from t2")
1085
+
1086
+ ```
1087
+
1088
+ 页面加载后,立刻显示 "Hello from t1"。当切换到 "t2" 页签,才会显示 "Hello from t2"。
1089
+
1090
+ ---
1091
+
893
1092
  ### scoped_style
894
1093
 
895
1094
  `scoped_style` 方法允许你创建限定在组件内部的样式。