?
具體步驟:登錄Apifoxhttps://app.apifox.com/
?
圈選復(fù)制上面的內(nèi)容粘貼到【接口地址列表】輸入框,自動(dòng)生成腳本代碼
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-703274.html
接口代碼生成工具源碼?
<template>
<!--
前往https://blog.csdn.net/qq_37860634/article/details/132709087
查看使用說(shuō)明
-->
<div :class="$options.name">
<div class="sg-head">接口代碼生成工具</div>
<div class="sg-container">
<div class="sg-start">
<div style="margin-bottom: 10px">接口地址列表</div>
<el-input
style="margin-bottom: 10px"
type="textarea"
:placeholder="`請(qǐng)粘貼apifox.com網(wǎng)站的內(nèi)容`"
v-model="textareaValue1"
:rows="30"
show-word-limit
/>
<el-button type="primary" @click="createAPI">生成接口列表</el-button>
</div>
<div class="sg-center">→</div>
<div class="sg-end">
<div style="margin-bottom: 10px">直接復(fù)制</div>
<el-input
style="margin-bottom: 10px"
type="textarea"
:placeholder="`請(qǐng)復(fù)制代碼`"
v-model="textareaValue2"
:rows="30"
show-word-limit
/>
<el-button type="primary" @click="copyAPI">復(fù)制</el-button>
</div>
</div>
</div>
</template>
<script>
export default {
name: "sgCreateAPI",
data() {
return {
textareaValue1: "",
textareaValue2: "",
apiPathPrefix: `/rp/`, //api路徑固定前綴(用于區(qū)別哪一個(gè)字符串才是路徑開頭)
};
},
watch: {
textareaValue1(newValue, oldValue) {
newValue && this.createAPI(newValue);
},
},
methods: {
createAPI(d) {
let texts = this.textareaValue1.split("\n").map((v) => v.split("\t").join(""));
let r = [];
texts.forEach((v, i, arr) => {
if (i % 3 === 0 && v) {
let path = arr[i + 2];
let apiPath = path.includes(this.apiPathPrefix)
? path.split(this.apiPathPrefix)[1]
: path;
apiPath.indexOf("/") === 0 && (apiPath = apiPath.substr(1));
r.push([arr[i], apiPath]);
}
});
let apis = [];
r.forEach((v) =>
apis.push(
`/* ${v[0]} */${v[1]
.split("/")
.slice(1)
.join("_")}({ data, r }) { this.__sd("post", \`\${API_ROOT_URL}/${
v[1]
}\`, data, r); },`
)
);
this.textareaValue2 = apis.join("\n");
this.copyAPI(apis);
},
copyAPI(d) {
this.$g.copy(this.textareaValue2, true);
},
},
};
</script>
<style lang="scss" scoped>
.sgCreateAPI {
width: 100%;
height: 100%;
position: absolute;
box-sizing: border-box;
padding: 20px;
.sg-head {
display: flex;
justify-content: center;
align-items: center;
font-size: 24px;
font-weight: bold;
color: #409eff;
margin-bottom: 10px;
}
.sg-container {
display: flex;
flex-wrap: nowrap;
& > .sg-start {
width: 50%;
flex-grow: 1;
}
& > .sg-center {
display: flex;
justify-content: center;
align-items: center;
flex-grow: 1;
margin: 0 10px;
font-size: 24px;
color: #409eff;
font-weight: bold;
}
& > .sg-end {
width: 50%;
flex-shrink: 0;
}
>>> textarea {
max-height: revert;
height: calc(100vh - 200px);
word-wrap: break-word;
word-break: break-all;
white-space: break-spaces;
}
}
}
</style>
生成的接口請(qǐng)求代碼是基于【Vue.js最新版】【基于jQuery Ajax】[sd.js]最新原生完整版for凱哥API版本_你摯愛的強(qiáng)哥的博客-CSDN博客【代碼】【最新版】【基于jQuery Ajax】[sd.js]最新原生完整版for凱哥API版本。https://blog.csdn.net/qq_37860634/article/details/129976375文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-703274.html
到了這里,關(guān)于【sgCreateAPI】自定義小工具:敏捷開發(fā)→自動(dòng)化生成API接口腳本(接口代碼生成工具)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!