vue.js - VueJS Filter Not Working -
why filter not work?
error says: [vue warn]: failed resolve filter: uppercase.
not sure why filter not working. also, best way code functionality? there ways this, or suggested ways? i'm not sure using $refs, maybe can simpler, effective use of reusable components.
i'm trying emulate ajax response using random message , 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">×</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>
the uppercase filter has been removed in vue.js 2.
https://vuejs.org/v2/guide/migration.html#built-in-text-filters-removed
you can use:
{{ text.touppercase() }}
as far structure of code goes, better off in method:
close: function() { this.alerttype= null; this.title= null; this.message= null; this.showalert= false; }
since duplicating twice different values.
Comments
Post a Comment