Vue Custom Filters Filter

 ) // id {string} // Definition {function}  

In the project, if there are multiple filters, then how can I register, globally, we have built a Filters folder in the project, as follows, Index.js It is an export file, readmore is a filter for string


file directory


// Index.js // Introduces all filter functions importmore from ‘./readmore’ ;/ exports on an object export default {readmore}; // Readmore.js // View more text Display ‘…’ let readmore = (text, length, suffix) => {if (text) {if (text.length
  <= length) return text;
  return text.substring(0,length) + suffix;
 return text;
export default readMore; 
Then it is processed in main.js:

Main.js to make global registration


// Global registered Custom Filter Import Filters from ‘./filters’;for (Let Key IN Filters) {Vue.Filter (key, value1, value2) => {Return Filters Key] (Val, ValuE1, VALUE2);};}

   // in TEST can be used. Vue is used 

{{‘text text’ | readmore (15, ‘…’)}}

  Summary <p html="readMore('文字文字' ,60,`...  

The above is the Vue custom FILTERS filter that Xiaobian gives you, I hope to have some Help, if you have any questions, please leave a message, the small package will reply to everyone in time. Thank you very much for your support for Tumi Cloud website!
© Copyright Notice
Just support it if you like
comment Grab the couch

Please log in to comment