Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
198
rated 0 times [  200] [ 2]  / answers: 1 / hits: 25579  / 7 Years ago, wed, january 24, 2018, 12:00:00

I has worked with Vue for several days, and meet some problem.



I use jQuery AJAX load data (text content) in template, title and description need to be ellipsis, I wrote the methods



methods:{
titleELLIPSIS:function(){
var title = self.articleList.title;//AJAX data
var titleLength = title.length;
var maxWidth = 15;
var newTitle = title.split(,maxWidth);
return title(function(ELLIPSIS){
if(titleLength>maxWidth){
for(var j=newTitle.length-1;j>0;j--){
delete newTitle[j];
var ELLIPSIS = self.innerHTML = newTitle.join('')+'...';
if(newTitle.length<=maxWidth){ break;}
return ELLIPSIS;
}
}
})

}
}


And my template is:



<h2 class=ellipsis-2>{{titleELLIPSIS}}</h2>


How could I return the ellipsis title in h2?



Please give me some idea.



By the way, the AJAX is success, because other data show correctly.


More From » vue.js

 Answers
8

Computed property is what you're looking for. Move titleEllipsis to computed section:


computed: {
titleELLIPSIS:function(){
var title = self.articleList.title;//AJAX data
var titleLength = title.length;
var maxWidth = 15;
var newTitle = title.split("",maxWidth);
return title(function(ELLIPSIS){
if(titleLength>maxWidth){
for(var j=newTitle.length-1;j>0;j--){
delete newTitle[j];
var ELLIPSIS = self.innerHTML = newTitle.join('')+'...';
if(newTitle.length<=maxWidth){ break;}
return ELLIPSIS;
}
}
})

}
}

[#55379] Sunday, January 21, 2018, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lelasamiraa

Total Points: 208
Total Questions: 99
Total Answers: 107

Location: Uzbekistan
Member since Tue, Nov 30, 2021
3 Years ago
lelasamiraa questions
Thu, Jul 16, 20, 00:00, 4 Years ago
Thu, Oct 17, 19, 00:00, 5 Years ago
Mon, Aug 5, 19, 00:00, 5 Years ago
Thu, Feb 7, 19, 00:00, 5 Years ago
;