Live2d Test Env

vue关于截取字符串并将字符串替换成指定格式

想了个需求,如题目

data:

                demo: 'bacdefghijk'

web:

 <h1>{{str(demo)}}</h1>

 methods:

 str(value) {
     return value.replace(value.substring(3, value.length - 4), '****')
 }

也可以在computed中使用,但限于知识,无法做到复用

web:

        <h1>{{str}}</h1>

computed:

  str() {
      return this.demo.replace(this.demo.substring(3, this.demo.length - 4), '****')
  }

这个问题研究了一上午,尚未解出。如有理解的,欢迎指教

不胜感激,以上。

posted @ 2020-02-07 12:34  致爱丽丝  阅读(10182)  评论(0编辑  收藏  举报