2

Im trying to use multiple filters but it's not working here is my code. It's not making it to lowercase it just removes spaces.

EDIT:

For the lowercase I want to use Vue js filter lowercase

<div class="col-md-4" :class="playerBio.current_team | lowercase | removespace ">

JS

    removespace( str ) {
        if( str ) {
            return str.replace(/\s+/g, '').toLowerCase();
        }
    }
3
  • Please add the code of your filters. Commented May 26, 2017 at 8:02
  • Your link is for Vue1. Are you sure that ask about [vuejs2]? In Vue2 you can chain filters Commented May 26, 2017 at 8:23
  • @KirillMatrosov sorry about that link in Vue1, but I'm currently using Vue 2 how can I achieve that? Commented May 26, 2017 at 8:31

2 Answers 2

5

Example:

new Vue({
  el: '#app',
  data: {
    myText: 'Hello There Vue'
  },
  mounted() {
    console.log(this.$refs['div']) // log this div
  },
  filters: {
    lowercase: function(value) {
      return value.toLowerCase()
    },
    removespace: function(value) {
      return value.replace(/\s/g, '')
    }
  }
});
<script src="https://unpkg.com/vue/dist/vue.js"></script>

<div id="app">
<div class="col-md-4" :class="myText | lowercase | removespace" ref="div"></div>
</div>

I edited my first answer, because it appears filters can be used with v-bind as shown above.

Sign up to request clarification or add additional context in comments.

Comments

2

@PenAndPapers, you should write your own filter for lowercase, because there is no ready filters in vers 2.

var demo = new Vue({
    el: '#demo',
    data: {
    	cls: "cL ass"
    },
    filters: {
      lowercase: function (value) {
        if (!value) return ''
        value = value.toString()
        return value.toLowerCase();
      },
      removespace( str ) {
          if( str ) {
              return str.replace(/\s+/g, '');
          }
      }
    }
})
.class
{
  height: 50px;
  width: 50px;
  background-color: red;
}
<script src="https://vuejs.org/js/vue.min.js"></script>
<div id="demo">
    {{cls | lowercase | removespace}}
    <div v-bind:class='cls | lowercase | removespace'></div>
</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.