[Vue] Create Filters in Vue.js

Just like in the command line, you can pipe a property through a filter to get a desired result. You can even chain them together!

 

<template>
    <section class="container">
        <h1 class="title">
            {{message | capitalize}}
        </h1>
    </section>
</template>

<style scoped>
.title
{
  margin: 50px 0;
}

</style>

<script>

  export default {
    data() {
      return {
        message: 'this is my vue!'
      }
    },

    filters: {
        capitalize(value) {
            return value.charAt(0).toUpperCase() + value.slice(1).toLowerCase();
        }
    },
  }

</script>

 

posted @ 2017-01-20 19:13  Zhentiw  阅读(326)  评论(0编辑  收藏  举报