JSFiddle - React, Tailwind, and code Playground

by Doris18

HTML

<div id="app" v-cloak>
    <section>
      <h2>过滤器的使用-添加前缀</h2>
      <p>{{352.11 | toRMB}}</p>
      <p>{{657 | toRMB}}</p>
      <p>{{657.22 | toFixed }}</p>
      <p>{{657.22 | toFixed | toRMB}}</p>
      <h2>多重参数</h2>
      <p>{{text}}</p>
      <p>{{text | readMore(20,'...')}}</p>
      <h2>链式过滤</h2>
      <p>{{money}}</p>
      <p>{{money|toFixed|toRMB}}</p>
    </section>
  </div>

CSS

[v-cloak]{
      display: none;
    }

JavaScript

Vue.filter('toRMB', function (value) {
      return `¥${value}`
    })

    new Vue({
      el: '#app',
      data: {
        text: 'hello I love u, will u love me ?',
        money: 826.26,
      },
      filters: {
        toFixed: function(money) {
          return money.toFixed(1)
        },
        Upper: function (value) {
          return value.toUpperCase();
        },
        Lower: function (value) {
          return value.toLowerCase();
        },
        readMore: function (value,length,suffix) {
          console.log(arguments);
          return value.substr(0,length) + suffix;
        },
      }
    })