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