1

Why does filter do not work?

Error says: [Vue warn]: Failed to resolve filter: uppercase.

Not sure why but filter is not working. Also, is this the best way to code this functionality? Are there any ways to do this, or the suggested ways? I'm not sure about using the $refs, maybe I can do this simpler, but with effective use of reusable components.

I'm trying to emulate an Ajax Response by using random message and status instead.

Link: JSBIN

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  <div id="app">  
    <login-alert ref="refalert"></login-alert>
    <p>
      <button @click="showme">Random Alert</button>
    </p>
  </div>
    <script src=" https://unpkg.com/vue"></script>
    <template id="template-alert">
  <div v-if="showAlert">
    <div :class="'alert alert-'+alertType+' alert-dismissible'" transition="fade">
      <button type="button" class="close" data-dismiss="alert" aria-hidden="true" v-on:click="close">&times;</button>
      <h4>{{title|uppercase}}!</h4>
      {{message}}
    </div>
  </div>
  </template>
  <script>
    Vue.component('login-alert', {
      template: '#template-alert',
      data: function() {
        return {
          alertType : null,
          title : null,
          message : null,
          showAlert : false
        }
      },
      methods: {
        close: function() {
          this.alertType= null;
          this.title= null;
          this.message= null;
          this.showAlert= false;
        },
        open: function(type, message) {
          this.alertType= type;
          this.title = type;
          this.message= message;
          this.showAlert= true;
        }
      }
    });

    var app = new Vue({
      el: '#app',
      methods: {
        showme: function() {
          var randomStatus = ['error', 'warning', 'success'];
          var randomMessage = ['Lorem Ipsum', 'Adolor Sit Amet', 'Abed Meepo'];
          var status = randomStatus[Math.floor(Math.random() * randomStatus.length)];
          var message = randomMessage[Math.floor(Math.random() * randomMessage.length)];
          this.$refs.refalert.open(status,message);
        }
      }
    });
  </script>
</body>
</html>
1
  • Possible duplicate of Filter with VueJS Commented Mar 20, 2019 at 11:37

1 Answer 1

4

The uppercase filter has been removed in Vue.js 2.

https://v2.vuejs.org/v2/guide/migration.html#Built-In-Text-Filters-removed

You can simply use:

{{ text.toUpperCase() }}

As far as the structure of your code goes, something like this is probably better off in a method:

close: function() {
  this.alertType= null;
  this.title= null;
  this.message= null;
  this.showAlert= false;
}

Since you are duplicating it twice but just with different values.

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

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.