首页 > 其他 > 详细

vue----05

时间:2020-05-22 23:08:03      阅读:74      评论:0      收藏:0      [点我收藏+]

1、组件参数效验

<div id="root">
   <counter :content="{a:1}""></counter>
   
</div>

<script>
    var counter = {
        props: {
            content: {
                type:String,
                required:true ,//此处指该参数是否为必传参数,
                default : ‘default‘ ,//默认值
                validator : function(value) {//此处为校验器,value代指传入的内容 
                    return (value.length > 5)
                }
            }
        },
        template:‘<div >{{content}}</div>‘,
        data: function() {
            return {
                
            }
        },
        methods: {
        
        }
    }

    var vm  = new Vue({
        el:"#root",
        data: {
            total: 0  
        },
        components: {
            counter:counter 
        },
        methods: { 
           handleChange: function(step) {//step指步长
                // this.total = this.$refs.one.number + this.$refs.two.number;
                this.total += step
                
           }
        }
    })
</script>

2、非props特性

props特性: 属性的传递不会表现在网页中

非props特性: 父组件向子组件传递了内容,子组件没有props, 属性的传递会表现在网页中

vue----05

原文:https://www.cnblogs.com/my-rw/p/12939998.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!