3👍
you can add a method that will get a portion of blog content.
methods: {
getContentPortion (content, maxSize) {
if(maxSize >= content.length) {
return content;
}
return `${content.substr(0, maxSize)}...`;
}
},
And then you can update your template with:
<b-card
title= blogs[0].title
img-src="https://placekitten.com/g/400/450"
img-alt="Image"
img-top
>
<b-card-text>
{{ getContentPortion(blogs[0].content, 10) }}
</b-card-text>
</b-card>
- [Vuejs]-How to access bound key of Vue.js list item?
- [Vuejs]-Transform v-model bound value in Vue.js
1👍
<b-card
:title=blogs[0].title
img-src="https://placekitten.com/g/400/450"
img-alt="Image"
img-top
>
<b-card-text>
{{blogs[0].content[:10]}}
</b-card-text>
</b-card>
This should work. Use v-bind
to use JS in HTML tags.
See more in the docs: https://v2.vuejs.org/v2/guide/class-and-style.html
- [Vuejs]-Email/verify with VusJS SPA and Laravel
- [Vuejs]-Is there no way to reliably work with slot content in Vue 3?
1👍
I’d recommend creating a filter.
Vue.filter('ellipse', function (value, size) {
if (!value) return ''
if (value.length < size) return value;
return `${value.substr(0, size)}...`;
})
Then you can easily reuse throughout your code:
{{ message | ellipse(50) }}
<p v-text="message | ellipse(50)"></p>
Source:stackexchange.com