可以使用Vue的计算属性来实现这个转换。

首先,在Vue的data中定义一个数组,包含['星期一', '星期二', '星期三', '星期四', '星期五']:

data() {
  return {
    weekdays: ['星期一', '星期二', '星期三', '星期四', '星期五']
  }
}

然后,在计算属性中使用Array的map方法将星期转换为对应的数字,并使用join方法将数字数组转换为字符串:

computed: {
  convertedWeekdays() {
    return this.weekdays.map(day => {
      return this.weekdays.indexOf(day) + 2;
    }).join(',');
  }
}

这样,convertedWeekdays计算属性的值就会是"2,3,4,5,6"。

vue将星期一 星期二 星期三 星期四 星期五转换为23456

原文地址: http://www.cveoy.top/t/topic/ij5o 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录