效果图
HTML
<!DOCTYPE html>
<html lang="zh-cn">
<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>
</head>
<body>
<div id="app">
<div>
<input v-model="length">mm
<br>
{{length|meter}}
</div>
<div>
<input type="text" v-model="price">
{{price|currency('$')}}
</div>
</div>
<script src="vue.js"></script>
<script src="main.js"></script>
</body>
</html>
JS
Vue.filter('meter',function(val,unit){
val=val||0;
unit=unit||'m';
return (val/1000).toFixed(2)+unit;
});
Vue.filter('currency',function(val,unit){
val=val||0;
unit=unit||'元';
return val+unit;
});
new Vue({
el:'#app',
data:{
price:100,
length:10,
}
})