概述
JS内容
另起一个js文件,命名为api.js
var Api = function () {
// api域名
this.DOMAIN = "https://test.com";
// 照片域名
this.IMG_DOMAIN = "";
// api链接
this.API_URLS = {
WIN: "blueprint/get",
...
};
this.getApiUrl = function (str) {
if (this.API_URLS[str] === undefined) {
alert("接口地址请配置正确!");
}
return this.DOMAIN + "/" + this.API_URLS[str];
};
};
引入
<script src="...js/api.js" type="text/javascript"></script>
使用
var api_url = (new Api).getApiUrl("WIN");
console.log(api_url);
输出
https://test.com/blueprint/get
最后
以上就是勤劳大白为你收集整理的常规Web项目,接口地址配置化的全部内容,希望文章能够帮你解决常规Web项目,接口地址配置化所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复