Vue 1.0 capitalize、uppercase、lowercase、json等都已被弃用。
Vue 2.0 需要自定义。如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> </head> <body> <div id="app"> <h1> {{ msg | capitalize }} </h1> <h1> {{ msg1 | uppercase }} </h1> <h1> {{ msg2 | lowercase }} </h1> <h1><pre> {{ massage | json(8) }} </pre></h1> <h1><pre> {{ massage1 | json(5) }} </pre></h1> <h1><pre> {{ msg | wrap('start','end') }} </pre></h1> </div> <script> Vue.filter('wrap',function (value,start,end) { return start +' ' + value +' ' + end }) var vm = new Vue({ el:'#app', data:{ msg:'i love you ?', msg1:'Are you sure ?', msg2:'sure!', massage:{ 1:'hello world!', 2:'Yes' }, massage1:{ 3:'hey jack!', 4:'hey' } }, filters:{ capitalize: function (value) { return value.charAt(0).toUpperCase()+value.slice(1); }, uppercase: function (value) { return value.toUpperCase(); }, lowercase: function (value) { return value.toLowerCase(); }, json: function (value,param) { // param最大为10 return JSON.stringify(value,null,param); } } }) </script> </body> </html>