VUE3给table的head添加popover筛选、时间去除时分秒、字符串替换某字符

1. VUE3给table的head添加popover筛选


      
        
      
      
        
        
      
const bondCodeSelection = ref()
let securityIds: any = ref([])
let bondCodeVisible = ref(false)

const bondCodeVisibleChange = () => {
  bondCodeVisible.value = false
  bondCodeSelection.value.blur()
}
//筛选下拉框选项,bondTenderStocks为接口获取数据列表
let selectIdData = computed(() => {
  let map = new Set()
  let securitys: any = []
  bondTenderStocks.value.forEach((item: any) => {
    if (map.has(item.secuId) === false) {
      map.add(item.secuId)
      securitys.push({
        text: item.secuId + ' ' + item.secuNm,
        value: item.secuId
      })
    }
  })
  return securitys
})

let displayData = computed(() => {
  let initData = JSON.parse(JSON.stringify(tableData.value))

  // 债券代码
  if (securityIds.value.length !== 0) {
    let securitySet = new Set()
    securityIds.value.forEach((security: any) => securitySet.add(security))
    initData = initData.filter((item: any) => securitySet.has(item.secuId))
  }

  return initData
})

2.时间去除时分秒

function getDate(date: any) {
  if (!date) {
    return ''
  }
    
    // 将字符串转换为 Date 对象  
    var date = new Date(dateString);  
  
    // 使用 toISOString 方法获取日期时间字符串的简化版本,然后提取年月日部分  
    var formattedDate = date.toISOString().split('T')[0];  
    return formattedDate
}

ex:date = "2023-11-02 00:00:00"

VUE3给table的head添加popover筛选、时间去除时分秒、字符串替换某字符_第1张图片

3.字符串替换某字符

function formatText(text: any) { if (!text) { return '' } let result = text if (text.indexOf('\n') >= 0) { let str = text.replace('\n', '') result = str.replace(/\n/g, '
') } return result } ex: 全部替换 let str = "\n债券代码:1680352.IB\n债券简称:16马经发债02\n发行量:17.5亿\n中标量:2.1"; let newStr = str.replace(/\n/g, "
"); //只替换第一个 let newStr = str .replace('\n', '')

你可能感兴趣的:(vue3,项目总结,vue.js,elementui,javascript)