Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display only a part of the name if characters exceed a limit in Vue.js

Tags:

I am trying to display a message once the user logs in.

In the case where number of characters exceed 8, how can I display only the first 8 characters of a name followed by ".." ? (Eg: Monalisa..)

new Vue({
    el: '#app',
    data: {
        username: 'AVERYLONGGGNAMMEEE'
    }
});

Here is my jsfiddle demo

like image 936
Inchara Raveendra Avatar asked Oct 09 '17 04:10

Inchara Raveendra


People also ask

What does $t mean in Vue?

Vuex is a state management pattern for vue. js. $t is the injected method from vue. js or Vue. i18n.

How do I hide components in Vue?

Conclusion. Vue gives you a bunch of good ways to hide the element on the screen. When using v-if="false" the element isn't rendered at all in the DOM. When using v-show="false" the element is rendered in the DOM, however, Vue applies the inline style display: none that hides the element completely.

What is component tag in Vue JS?

<component> is a special vue element that is used in combination with the is attribute.


1 Answers

Here is my answer fiddle : ANSWER-DEMO

<div id="app">
  <div v-if="username.length<8">Welcome, {{ username }}</div>
  <div v-else>Welcome, {{ username.substring(0,8)+".." }}</div>
</div>
like image 68
Inchara Raveendra Avatar answered Nov 09 '22 11:11

Inchara Raveendra