class PlaylistViewNewModel (var playlist: Playlist?) : ViewModel() {var limit = 100private val name by lazy {//lazy 只会执行一次playlist?.id}//重写get方法 每次使用都是调用get(方法)private val playlistId: Stringget() = playlist?.id ?: ""}使用初始化
mPlaylistVM = PlaylistViewNewModel(null)设置变量PlaylistVM?.playlist = playlistViewModel 初始化fragmentprivate val mMyPlaylistVM by lazy {ViewModelProvider(this)[MyPlaylistViewModel::class.java]}父fragment内共用private val mMyPlaylistVM1 by lazy {ViewModelProvider(requireParentFragment())[MyPlaylistViewModel::class.java]}activity内共用private val mPlayVM by lazy {ViewModelProvider(requireActivity())[PlayViewModel::class.java]}