Vue.js:如何在Vue.js中删除大括号“ {}”

问题描述

我有这样的数据:

{
    success: true,message: "success",data: {
        schedule_id: 2,estimated_practice_time: "20",day: "{0,1}",from_time: "{08:00:00,09:00:00}",until_time: "{18:00:00,19:00:00}"
    }
}

现在,这是我的结果:

enter image description here

我只想显示“ day”上的值,不带花括号

0,1

解决方法

创建一个计算属性,您可以在其中将大括号替换为空字符串:

computed:{
     customDay(){
         return this.obj.data.day.replace(/[{}]/g,'');
   }
}
,

您可以使用regex来实现

let a = '{1,2}'
a = a.replace(/[{}]/g,'');
console.log(a)