image.png

代码

<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue.js中过滤器的使用</title>
    <script src="https://static.gzj2001.com/vue/vue.js"></script>
</head>
<body>
    <div id="app">
     {{message}}
     <br>
     {{message | daxie}}
    <script>
        new Vue({
            el:"#app",
            data:{
                message:"welcome to cnhk"
            },
            filters:{
                daxie:function(cs){
                    if(!cs) return "";
                    cs = cs.toString();
                    return cs.charAt(0).toUpperCase()+cs.slice(1);
                }
            }
        })
    </script>
</body>
</html>