Pen*_*ers 2 javascript frontend filter vue.js vuejs2
我试图使用多个过滤器,但它在这里不起作用是我的代码。它不是小写,它只是删除空格。
编辑:
对于小写,我想使用 Vue js 过滤器小写
<div class="col-md-4" :class="playerBio.current_team | lowercase | removespace ">
Run Code Online (Sandbox Code Playgroud)
JS
removespace( str ) {
if( str ) {
return str.replace(/\s+/g, '').toLowerCase();
}
}
Run Code Online (Sandbox Code Playgroud)
例子:
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, '')
}
}
});Run Code Online (Sandbox Code Playgroud)
<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>Run Code Online (Sandbox Code Playgroud)
我编辑了我的第一个答案,因为看起来filters 可以用于v-bind如上所示。
| 归档时间: |
|
| 查看次数: |
10540 次 |
| 最近记录: |