vue js中的换行符

dfty9e19  于 2022-11-25  发布在  Vue.js
关注(0)|答案(1)|浏览(140)

Vue js代码:-

getTitleText(){
  let mainTitle = "";

  let getTitle = this.titleText;
  let countGetTitle = getTitle.split(" ").length;
  if(countGetTitle > 4){
      mainTitle = getTitle.replace(/(\S+\s*){1,4}/g, "$&\n");
  }
  console.log("countGetTitle = ",countGetTitle);
  console.log("getTitle = ",mainTitle);
    return mainTitle;
},

HTML:-

<div class="end-workout-title1">{{ getTitleText() }}</div>

但是我在输出中得到了一整行。请帮助我得到worng的地方

wtlkbnrh

wtlkbnrh1#

在类中添加white-space:pre规则:

.end-workout-title1{
   ...
   white-space:pre
}

相关问题