Vue.component("http-cors-header-config-box", { props: ["value"], data: function () { let config = this.value if (config == null) { config = { isOn: false, allowMethods: [], allowOrigin: "", allowCredentials: true, exposeHeaders: [], maxAge: 0, requestHeaders: [], requestMethod: "", optionsMethodOnly: false } } if (config.allowMethods == null) { config.allowMethods = [] } if (config.exposeHeaders == null) { config.exposeHeaders = [] } let maxAgeSecondsString = config.maxAge.toString() if (maxAgeSecondsString == "0") { maxAgeSecondsString = "" } return { config: config, maxAgeSecondsString: maxAgeSecondsString, moreOptionsVisible: false } }, watch: { maxAgeSecondsString: function (v) { let seconds = parseInt(v) if (isNaN(seconds)) { seconds = 0 } this.config.maxAge = seconds } }, methods: { changeMoreOptions: function (visible) { this.moreOptionsVisible = visible }, addDefaultAllowMethods: function () { let that = this let defaultMethods = ["PUT", "GET", "POST", "DELETE", "HEAD", "OPTIONS", "PATCH"] defaultMethods.forEach(function (method) { if (!that.config.allowMethods.$contains(method)) { that.config.allowMethods.push(method) } }) } }, template: `
| 启用CORS自适应跨域 |
启用后,自动在响应Header中增加对应的 |
| 允许的请求方法列表 |
[添加默认]。 |
| 预检结果缓存时间 |
秒
|
| 允许服务器暴露的Header |
|
| 实际请求方法 |
|
| 仅OPTIONS有效 |
选中后,表示当前CORS设置仅在OPTIONS方法请求时有效。 |