Split Function in vue.js

Example:    

               

linked_charges_name from the API response is like “vendbill-1234” and needs to separate “vendbill-” and display the number only.

HTML:

   <div v-if="item.transaction_matches.includes('JE')">
     <a :href="getJournalEntryUrl(item)" class="text-black-500" target="_blank" rel="noopener noreferrer">
       {{ extractAfterDash(item.linked_charges_name) }}
     </a>
   </div>

Function:

  methods: {
   extractAfterDash(value) {
      return value.split(',').map(item => item.split('-')[1]).join(', ');
    }
},

extractAfterDash is the function and it should be called near the name like given below:

{{ extractAfterDash(item.linked_charges_name) }}

OUTPUT: 1234

Leave a comment

Your email address will not be published. Required fields are marked *