2024-12-20
class FruitViewModel: ObservableObject{
//Publish与State一样
@Published var fruitArray: [FruitModel] = []
@Published var isLoading: Bool = false
}
主视图:
@StateObject var fruitViewModel: FruitViewModel = FruitViewModel()
子视图:
@ObservedObject var fruitViewModel: FruitViewModel