<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="app">
<input type="text" v-model='msg'>
<div>{{msg|upper}}</div>
<div>{{msg|upper|lower}}</div>
<div :abc='msg|upper'>测试数据</div>
</div>
<script type="text/javascript" src="./js/vue.js"></script>
<script>
/* 侦听器 监听用户变化*/
/* Vue.filter('upper', function(val) {
return val.charAt(0).toUpperCase() + val.slice(1);
}); */
Vue.filter('lower', function(val) {
return val.charAt(0).toLowerCase() + val.slice(1);
})
var vm = new Vue({
el: '#app',
data: {
msg: ''
},
filters: {
upper: function(val) {
return val.charAt(0).toUpperCase() + val.slice(1);
}
}
})
</script>
</body>
</html>
标签:function,upper,39,vue,val,Vue,msg,slice,过滤器 From: https://blog.51cto.com/u_15460007/6048837