Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
651 views
in Technique[技术] by (71.8m points)

vue class绑定与过滤器结合时报错

我想让a+b>5的时候,给p标签一个big类,我使用了过滤器,但是报错了.
请问这是为什么,有什么其他解决方法吗?

[Vue warn]: Invalid expression. Generated function body:  {'big':scope.item
warn @ vue.js:1023
3vue.js:1023 [Vue warn]: Failed to resolve filter: isBig
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <script src="http://cdn.bootcss.com/vue/1.0.26/vue.js"></script>
    <style type="text/css">
        .big{
            background: gray;
        }
    </style>
</head>
<body>

<div id="saiku">
    <p v-for="item in list" class="{'big': item | isBig item.a item.b}">{{item.name}}</p>
</div>

<script type="text/javascript">
    'use strict';
    var vm = new Vue({
        el: '#saiku',
        data: {
            list:[
                {a:1, b:2, name: 'aaa'},
                {a:11, b:2, name: 'bbb'},
                {a:1, b:2, name: 'ccc'}
            ]
        }
    });

    Vue.filter('isBig', function(v,a,b){

        if(a+b > 5){
            return true;
        }
        else{
            return false;
        }
    });
</script>

</body>
</html>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

不要用过滤器,用method,还有class前面要加":"冒号或者"v-bind:"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...