我很难理解为什么我必须在调用此视图时提供名为 vm 的弹出视图依赖项,因为它是可观察的
struct ContentView: View {
@State private var showPopup1 = false
var body: some View {
VStack {
Button(action: { withAnimation { self.showPopup1.toggle()}}){
Text("showPopup1") }
Text("title")
DetailView() /// this line shows error
}
}
}
struct DetailView:View {
@ObservedObject var vm:ViewModel
var body : some View {
Text("value from VM")
}
}
class ViewModel: ObservableObject {
@Published var title:String = ""
}