Androids compose / state documentation包含一个涉及神秘 viewModel()
的样本函数或方法,但由于文档遗漏了所有导入语句,我无法终生弄清楚这个函数的来源..
最佳答案
您可以查看official doc :
you can access a
ViewModel
from any composable by calling theviewModel()
function.
To use the
viewModel()
functions,add theandroidx.lifecycle:lifecycle-viewmodel-compose:$latestVersion
dependency to yourbuild.gradle
file.
最后使用:
import androidx.lifecycle.viewmodel.compose.viewModel
关于android - Android Compose State 文档中的 "viewModel()"方法来自哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67753666/