vue过滤器的使用

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>

</head>
<body>
<div id="app">
<h1>{{666.66222 | toRMB}}</h1>
<h1>{{888.33388 | toFixed}}</h1>
<h1>{{money | toFixed | toRMB}}</h1>
<h1>{{text | readMore(15,'...')}}</h1>
</div>
</body>
</html>
<script>
Vue.filter("toRMB",function(value){
return `¥${value}`;
})

new Vue({
el:"#app",
data:{
money:292.59,
text:"hello world,hello vue"
},
filters:{
toFixed:function(money){
return money.toFixed(1)
},
readMore:function(value,length,suffix){
console.log(arguments);
return value.substr(0,length) + suffix
}
}
})
</script>
posted @ 2019-08-11 17:28  手可摘星辰htss  阅读(244)  评论(0编辑  收藏  举报