spring-boot - Vue数据区分同名的不同id
问题描述
所以我试图在vue中做这个post方法:
问题是以下代码:
我的Vue页面:
<template>
<div class="submit-form">
<div class="form-group">
<label for="coalition">Coalition Name</label>
<input
class="form-control"
id="coalition"
required
v-model="coalition.name"
name="coalition"
/>
</div>
<div class="form-group">
<label for="date">Date</label>
<input
type="date"
id="date"
required
v-model="coalition.date"
name="description"
/>
</div>
<button @click="saveCoalition" class="btn btn-success">Submit</button>
<p>{{message}}</p>
<!-- <div>-->
<!-- <button class="btn btn-success" @click="newParty">Add</button>-->
<!-- </div>-->
</div>
</template>
<script>
import CoalitionDataService from "../../services/CoalitionDataService";
import jwt_decode from "jwt-decode";
import HomeDataService from "../../services/HomeDataService";
export default {
name: "AddCoalition",
data() {
return {
coalition: {
id: null,
name: "",
date: "",
account: {
id: ""
}
},
message:""
};
},
methods: {
getUserId(){
//Retrieve JSON WEB TOKEN
try {
var token = localStorage.getItem("Authorization")
var decoded = jwt_decode(token);
var username = decoded[Object.keys(decoded)[0]];
HomeDataService.getId(username)
.then(response => {
this.coalition.account.id = response.data.id;
console.log(response.data.id)
})
}
catch (e){
console.log("No user is logged in")
}
return this.coalition.account.id
},
saveCoalition() {
var data = {
name: this.coalition.name,
description: this.coalition.description,
date: this.coalition.date,
account: {
id: this.getUserId()
}
};
CoalitionDataService.create(data)
.then(response => {
this.coalition.id = response.data.id;
console.log(response.data);
this.message = 'The Coalition was created successfully!';
})
.catch(e => {
console.log(e);
});
},
newParty() {
this.coalition = {};
}
}
}
问题是程序无法区分我得出这个结论coalition.account.id
的正常值coalition.id
,因为当我单击 id 时,另一个 Id 也会突出显示,就像它们是相同的 id 一样(但它们不应该是)。
我找不到解决此问题的方法。谁能帮我在vue中从邮递员那里发帖?谢谢!
笔记:
给出了想要的console.log(response.data.id)
值,这样就可以按照我想要的方式工作。
解决方案
推荐阅读
- asp.net - EF Core 迁移:无法加载程序集“AssemblyName”
- html - 通过 CSS 在 img 顶部的水平和垂直线
- spring-boot - FeignClient API-Call with application/x-www-form-urlencoded HEADER
- php - 从电子邮件主题中提取 id 的正则表达式
- python - python - 发送带有 3 个反斜杠的命令
- unicode - 应用程序如何知道字符编码?
- json - 通过单个字符串访问嵌套的 JSON 对象属性
- javascript - 如何在jslt foreach循环内的html元素上触发onchange事件?
- datastage - DataStage中Change Capture阶段和Difference阶段的区别
- angular - Angular 7 在 docker 中不工作,npm 安装不继续