参考书籍《Vue.js快跑:构建触手可及的高性能Web应用》第1章 Vue.js基础-----1-15过滤器
Vue.js 允许你自定义过滤器,可被用于一些常见的文本格式化。
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>过滤器title>
head>
<body>
<div id="app">
过滤前的值:<input type="text" v-model="message"><br>
<p>过滤后的值:{{message | capitalize}}p>
div>
<script src="https://unpkg.com/vue">script>
<script>
new Vue({
el: "#app",
data: {
message: "andy"
},
filters: {
capitalize: function (value) {
if (!value) return ''
value = value.toString();
return value.charAt(0).toUpperCase() + value.slice(1);
}
}
})
script>
body>
html>