我尝试使用ValidationObserver用vee-validate 3.0创建小提琴, 但是我遇到了一个问题,那就是尝试添加行:
import {ValidationObserver, ValidationProvider, extend} from 'vee-validate'
import {required, email, url} from 'vee-validate/dist/rules'
我在控制台中出错:
Uncaught SyntaxError: Cannot use import statement outside a module
此错误保存: https://jsfiddle.net/a6dL7yfc/2/
怎么能做到完美?
答案 0 :(得分:1)
从CDN加载时,不能使用func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
var url = navigationAction.request.url;
let scheme = url!.scheme;
// open local scheme in WebView
if (scheme == "file") {
decisionHandler(.allow);
}
// needed to show google maps icons for controls like zoomControl and streetViewControl
else if (scheme == "about") {
decisionHandler(.allow);
}
// other schemes like fb/http/https/mailto open in external application
else {
UIApplication.shared.openURL(url!);
decisionHandler(.cancel);
}
}
。而是将所有内容公开为全局import
对象的属性。
例如,VeeValidate
是ValidationObserver
。
更改这些:
VeeValidate.ValidationObserver
对此:
import {ValidationObserver, ValidationProvider, extend} from 'vee-validate'
import {required, email, url} from 'vee-validate/dist/rules'
第一行现在应该可以工作,但是第二行仍然会失败。要解决此问题,您还需要将vee-validate URL更改为const {ValidationObserver, ValidationProvider, extend} = VeeValidate
const {required, email, url} = VeeValidate.Rules
,而不是vee-validate.full.js
。完整版本包括规则。
如果要在HTML部分中指定模板,则适用于in-DOM模板的一般警告。例如您需要使用kebab-case作为模板中的组件名称:vee-validate.js
。