找不到viewModels,viewModels()
谷歌官方文档上学习mvvm,当我写到private val model: UserViewModel by viewModels()
时,viewModels()爆红,查了资料,找到gradle,添加依赖
dependencies{ implementation "androidx.activity:activity-ktx:1.2.0"//新添加 implementation "androidx.fragment:fragment-ktx:1.3.0" implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'//我的文件已有的 implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1' }