vue过滤器的使用

好久不见. 提交于 2019-11-26 23:51:39
<!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>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!