1. Global writing
Definition:
Vue. Filter ('id',function (params) {function()})Copy the code
Use:
The < div > {{test | filter1 (params)}} < / div > / / params can omit / / multiple filters can also be used serial < div > {{test | filter1 | filter2 | filter3}} < / div >Copy the code
Practice: use a filter to hide 4 digits in the middle of the phone number
First define the filter:
Filter ('phoneHide',function (phone) {let phoneArr = [...phone]; Let resStr = "phonearr.map ((res,index)=>{if(index > 2 && index< 7){resStr += '*'; }else { resStr += res } }) return resStr })Copy the code
Use filters:
<span>{{'17712345678'|phoneHide}}</span>
Copy the code
End result: