Javascript console.log和查询字符串中的值不同
VueJ是这里的初学者,我有一个预订系统,它使用一个日期选择器和两个数字输入(一个用于成人,一个用于儿童)以及使用Javascript console.log和查询字符串中的值不同,javascript,vuejs2,Javascript,Vuejs2,VueJ是这里的初学者,我有一个预订系统,它使用一个日期选择器和两个数字输入(一个用于成人,一个用于儿童)以及使用axios.get获取值,通过签入、签出和房间容量检查可用性。签入和签出工作正常,但RoomCapacity在查询字符串params中不保留任何内容,但在控制台日志记录时,它会显示该值。 和 以下是Vue代码: <b-tab title="Search Rooms" :disabled="step !== 0">
axios.get
获取值,通过签入、签出和房间容量检查可用性。签入和签出工作正常,但RoomCapacity在查询字符串params中不保留任何内容,但在控制台日志记录时,它会显示该值。
和
以下是Vue代码:
<b-tab title="Search Rooms" :disabled="step !== 0">
<div class="date">
<p>Pick a date:</p>
<!-- <date-picker v-model="time1" valueType="format" range ></date-picker> -->
<HotelDatePicker
format="DD/MM/YYYY"
@check-in-changed="updateCheckIn($event),searchCheckIn($event)"
@check-out-changed="updateCheckOut($event), searchCheckOut($event)"
></HotelDatePicker>
</div>
<div class="guestCount">
<p>Number of adults:</p>
<InputNumber :max="14" :min="1" v-model="bookForm.AdultCount" size="large"></InputNumber>
<br />
<p>Number of kids:</p>
<InputNumber :max="10" :min="0" v-model="bookForm.KidCount" size="large"></InputNumber>
<br />
</div>
<br/>
<b-button
@click="step = 1; searchRooms(); check(); totalGuest();"
variant="primary"
>Check Available Rooms</b-button>
</b-tab>
方法:
searchRooms(){
axios.get("http://localhost:3000/searchRooms",{
params:{
CheckInDate: this.searchForm.CheckInDate,
CheckOutDate: this.searchForm.CheckOutDate,
RoomCapacity: this.searchForm.RoomCapacity,
}
})
.then((res)=>{
if(res.data[0]){
// no problem
if(res.data[1].length){
//rows retrieved
this.roomList=res.data[1]
this.notice=""
this.err_msg=""
}else{
//no matching row
this.notice="No rooms found"
this.roomList=[]
this.err_msg=""
}
}else{
this.err_msg = res.data[1]
this.roomList=[]
this.notice=""
}
})
.catch((err)=>{
this.err_msgP="AJAX error"
this.PalacioRooms=[]
this.noticeP=""
})
},
totalGuest(){
let totalGuest = this.bookForm.KidCount + this.bookForm.AdultCount;
this.searchForm.RoomCapacity = totalGuest.toString();
},
check(){
console.log(this.searchForm)
},
我尝试将
房间容量
设为0,但问题相同,它只是保持为零。关于您的代码,我没有足够的信息来确定这一点,但在大多数情况下,如果console.log显示的是Vue本身以外的另一个值,则似乎知道这是由于Vue的getter和setter在当前JS事件周期中无法识别的值更改。
如果在Vue上下文之外使用自己的类实例方法来更改实例的属性,则可能会发生这种情况。最好在文档中解释一下:
要解决此问题,可以使用$set命令手动触发Vue的反应。打印对象,但控制台仅在展开对象时评估该对象的内容。因此,当记录时,您不会得到对象的状态,而是得到当前状态。如果你在同一时间更新了它(而且你似乎已经做到了),那将会有所不同。哦,谢谢你的链接,有点让我明白了方向
searchRooms(){
axios.get("http://localhost:3000/searchRooms",{
params:{
CheckInDate: this.searchForm.CheckInDate,
CheckOutDate: this.searchForm.CheckOutDate,
RoomCapacity: this.searchForm.RoomCapacity,
}
})
.then((res)=>{
if(res.data[0]){
// no problem
if(res.data[1].length){
//rows retrieved
this.roomList=res.data[1]
this.notice=""
this.err_msg=""
}else{
//no matching row
this.notice="No rooms found"
this.roomList=[]
this.err_msg=""
}
}else{
this.err_msg = res.data[1]
this.roomList=[]
this.notice=""
}
})
.catch((err)=>{
this.err_msgP="AJAX error"
this.PalacioRooms=[]
this.noticeP=""
})
},
totalGuest(){
let totalGuest = this.bookForm.KidCount + this.bookForm.AdultCount;
this.searchForm.RoomCapacity = totalGuest.toString();
},
check(){
console.log(this.searchForm)
},