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
470 views
in Technique[技术] by (71.8m points)

vue.js关于组件里面的input事件的疑问

如下代码vue在$emit`里面的input`参数到底值得是什么意思?还请指点一下,谢谢

<body>

<div id="app">
    你现在的银行卡余额是{{totale}}
    <!-- <appcom @change="handletotel"></appcom> -->
    <appcom v-model=" totale"></appcom>
</div>
<script>
    var cl = new Vue({
        el: '#app',
        data: {
            jk: 'this is father',
            totale: 2000 /*银行卡余额是2000元*/
        },
        methods: {
            // handletotel(value){
            //        //此处的形参value就是传递过来的数值
            //        this.totale=value;
            // }
        },
        components: {
            'appcom': {
                template: '<div>
                <div @click="haderplus">+1000</div>
                <div @click="hadercl">-1000</div>
                </div>',
                /*为什么{{c}}会被渲染出来*/
                props: ['kl'],
                data() {
                    return {
                        count: 2000
                    }
                },
                methods: {
                    haderplus() {
                        this.count = this.count + 1000;
                        this.$emit('input', this.count)
                    },
                    hadercl() {
                        this.count = this.count - 1000;
                        this.$emit('input', this.count);
                    }
                }
            }
        }

    })
</script>

</body>


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

1 Reply

0 votes
by (71.8m points)

v-model的语法糖,不过组件props应该有value传入


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

...