Javascript 从下拉菜单中选择新月份将清除Vuejs中的日期下拉列表
我有三个下拉菜单,分别代表出生日期、月份和年份:Javascript 从下拉菜单中选择新月份将清除Vuejs中的日期下拉列表,javascript,html,arrays,vue.js,drop-down-menu,Javascript,Html,Arrays,Vue.js,Drop Down Menu,我有三个下拉菜单,分别代表出生日期、月份和年份: <input-select id="dateOfBirth" label="Day" :name="'dateOfBirth' | hashcode" :option-default="select dat" :option-list="birthDates" :v-model="birthdate" :value="birthdate"</input-select> <input-sele
<input-select
id="dateOfBirth"
label="Day"
:name="'dateOfBirth' | hashcode"
:option-default="select dat"
:option-list="birthDates"
:v-model="birthdate"
:value="birthdate"</input-select>
<input-select
id="monthOfBirth"
label="Month"
:name="'monthOfBirth' | hashcode"
:option-default="select month"
:option-list="birthMonth"
v-model="birthmonth"
:value="birthMonth"></input-select>
<input-select
id="yearOfBirth"
label="Year"
:name="'yearOfBirth' | hashcode"
:option-list="birthYears"
:option-default="select year"
v-model="birthyear"
:value="birthyear"
></input-select>
确保您的v-model
出生日期
未在代码中的任何其他位置更新。用计算机或手表。这可能就是原因。另外,我注意到您同时使用了v-model
和:value
。尝试删除:值
data: function () {
return {
//initiating the array which would show the dates
birthdate:[],
numDates:''
...
methods: {
//the function that would repopulate the birthdate[] array
birthdateValueList(){
//erasing the values of the existing array
this.birthdates = []
//adding new values
let i = 1;
//numDates is defined in another function based on the month selected, please see below
while (i <= this.numDates){
this.birthdates.push(i);
i ++;
}
...
// watching the birthmonth drop down and setting the number days for that month
// this is where we define numDates
watch: {
birthmonth:function(){
if(this.birthmonth === "April" || this.birthmonth === "June" || this.birthmonth === "September" || this.birthmonth === "November"){
this.numDates = 30
}else if (this.birthmonth === "February" && this.leapYear){
this.numDates = 29
}
else if(this.birthmonth === "February" && !this.leapYear){
this.numDates = 28
}
else {
this.numDates = 31
}
...
// and then a computed property to do some formatting and returning the final array
computed: {
birthDates: function(){
var list = JSON.parse(JSON.stringify(this.birthdates));
var birthdateDates = this.generateNewList(list);
return birthdateDates;
},