import SwiftUI
import WebKitstruct ContentView: View {var body: some View {VStack {Text("测试")WebView(urlString: "https://aweb123.com").frame(maxWidth: .infinity, maxHeight: .infinity) // 让 WebView 占据整个可用空间}.frame(minWidth: 200, minHeight: 200) // 设置 ContentView 的最小尺寸}
}struct WebView: NSViewRepresentable {let urlString: Stringfunc makeNSView(context: Context) -> WKWebView {let webView = WKWebView()return webView}func updateNSView(_ nsView: WKWebView, context: Context) {if let url = URL(string: urlString) {let request = URLRequest(url: url)nsView.load(request)}}
}struct ContentView_Previews: PreviewProvider {static var previews: some View {ContentView()}
}#Preview {ContentView()
}
如果空白
那就是这个权限没有打开