不使用v-bind,传值给props的都是字符串

当向props传递数字,布尔值,数组,对象时,不使用v-bind,那传递的仅仅是字符串 。对比下区别:

 <div id="app">
    <my-component message="[1,2,3]"></my-component>
    <my-component :message="[1,2,3]"></my-component>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script>
<script>
    Vue.component('my-component',{
        props:['message'], 
        template:'<div>{{ message.length }}</div>'
    })

    var app = new Vue({
        el:'#app'
    })
</script> 

执行结果:

7 
3

You may also like...