需求:
每种类型不一样,点击其调后端接口返回的数据就不一样,总体一种分为两种:一种是会直接返回即将要跳转的路径,另外一种就是需要根据后端返回的数据,动态的创建form表单及input,并将form表单数据提交至指定的url。
<div v-for="application in Applications" :key="application.index">
<v-card
class="float-left application-item ma-3"
elevation="0"
@click="toCurUrl(application)"
>
<v-card-text
class="d-flex flex-column align-center text-center pt-10"
>
<v-img
:src="require('@/assets/imgs/' + application.type + '.png')"
max-width="40"
></v-img>
<a class="mt-4 text-decoration-none black--text">
{{ application.name }}
</a>
</v-card-text>
</v-card>
</div>
expert default{
data(){
return {
applications: []
}
},
methods:{
toCurUrl(item) {
this.$http
.post(`/api/${item.id}/aaa`)
.delegateTo(api_request)
.then(data => {
if (data.type === "REDIRECT_URL") {
location.href = data.action;
} else {
let { action, method, inputs } = data.action;
let form = document.createElement("form");
form.action = action;
form.method = method;
for (let i = 0; i < inputs.length; i++) {
let input = document.createElement("input");
input.name = Object.keys(inputs[i])[0];
input.value = Object.values(inputs[i])[0];
form.appendChild(input);
}
document.body.appendChild(form).submit();
}
})
.catch(({ code, message }) => {
throw `获取数据失败:${this.$t("api." + code)}, 额外信息: ${this.$t(
"api." + typeof message === "string"
? message
: JSON.stringify(message)
)}`;
})
.delegateTo(this.$snackbar.delegateError);
}
}
}