父組件代碼 <template>
<div>
<item1 :test="{test:1}"></item1>
</div>
</template>子組件代碼<template>
<div>
<input v-model="test.test">
</div>
</template>
<script>
export default {
props: {
test: Object
}
}</script>此時(shí)我們?cè)谧咏M件input框中任意修改是不報(bào)錯(cuò)的,應(yīng)為我們通過父組件傳過來的值是復(fù)合類型數(shù)據(jù),當(dāng)我們改為普通類型的數(shù)據(jù)時(shí)就會(huì)報(bào)錯(cuò),如下報(bào)錯(cuò)的原因是我們修改如下父組件代碼 <template>
<div>
<item1 :test="1"></item1>
</div>
</template>子組件代碼<template>
<div>
<input v-model="test">
</div>
</template>
<script>
export default {
props: {
test: Number
}
}</script>有誰能解釋下么?
vue 父組件向子組件通過props傳遞數(shù)據(jù)不能用v-model綁定?
天涯盡頭無女友
2018-07-05 12:12:38