选择阴历日期
月份列表:monthList = [‘正月’, ‘二月’, ‘三月’, ‘四月’, ‘五月’, ‘六月’, ‘七月’, ‘八月’, ‘九月’, ‘十月’, ‘十一月’, ‘十二月’]
日列表 daysList = [‘初一’, ‘初二’, ‘初三’, ‘初四’, ‘初五’, ‘初六’, ‘初七’, ‘初八’, ‘初九’, ‘初十’, ‘十一’, ‘十二’, ‘十三’, ‘十四’, ‘十五’, ‘十六’, ‘十七’, ‘十八’, ‘十九’, ‘廿十’, ‘廿一’, ‘廿二’, ‘廿三’, ‘廿四’, ‘廿五’, ‘廿六’, ‘廿七’, ‘廿八’, ‘廿九’, ‘三十’]
选中的日期格式是this.realBirth 正月廿九 格式
const key2 = daysList.findIndex(item => this.realBirth.split(‘月’)[1].includes(item))
查找日期的下标时 查不到廿九
const key2 = daysList.findIndex(item => this.realBirth.split(‘月’)[1]== item)
1 百度搜到用转码
toUnicodeFun(data) {
if (data == ‘’ || typeof data == ‘undefined’) return ‘请输入汉字’
var str = ''
for (var i = 0; i < data.length; i++) {
str += '\\u' + data.codePointAt(i).toString(16)
}
console.log(str,"str");
return str
},
对于this.realBirth.split('月')[1] 转码后多了个/u200c 所以导致转码后的 廿九 和this.realBirth.split('月')[1] 的廿九不等 匹配不到
2 用正则匹配
const regex1 = new RegExp(${this.realBirth.split('月')[0]}月, ‘g’)
const regex2 = new RegExp(${this.realBirth.split('月')[1]}, ‘g’)
也无法匹配到 廿九
3 在其他项目里 是可以查到的 测试回归原本方法
const key2 = daysList.findIndex(item => this.realBirth.split(‘月’)[1].includes(item))
成功查到
对于月份
const key2 = daysList.findIndex(item =>( this.realBirth.split(‘月’)[0]+‘月’).includes(item))查找失败 无法匹配成功
const key1 = monthList.findIndex(item =>( item.includes(this.realBirth.split(‘月’)[0]+‘月’))) 匹配成功
vue2 有这个问题 vue3项目 没有出现这个问题 不知道为啥 我理解的item 跟this.realBirth.split(‘月’)[0]+‘月’) 的值应该是一样的啊

5万+

被折叠的 条评论
为什么被折叠?



