1、声明私有过滤器和全局过滤器
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div id="app"> <p>message的值是:{{message | capi}}</p> </div> <script src="lib/vue-2.6.12.js"></script> <script> <!-- 定义全局过滤器 --> Vue.filter('capi', (str) => { const first = str.charAt(0).toUpperCase() const other = str.slice(1) return first + other }) const vm = new Vue({ el: '#app', data: { message: 'hello vue.js' }, methods: {}, // 私有过滤器 filters: { capi(val) { const first = val.charAt(0).toUpperCase() const other = val.slice(1) return first + other } } })</script> </body> </html>
标签:vue,const,val,other,capi,message,first From: https://www.cnblogs.com/record-100/p/17814683.html