2021年6月8日 星期二

koin 注入 viewModel 時用 byVewModel 會無法 launch viewModelScope, 須改用getViewmodel

情境:

使用 koin "io.insert-koin:koin-android:3.0.2"

viewModel 中使用 viewModelScope.launch {}

在 viewpager 右滑多個 fragment 後,往回滑,在 fragment 重建 view 後,viewModel 跑不進 viewModelScope.launch {} 的 lambda ,在 官方 issue 看到了解法(連結),就是不要使用 byViewModel{} 而是使用 getViewModel(),解是解了,但是為什麼呢?!



沒有留言:

張貼留言