vue子组件更改属性

严格来说,Vue子组件不能随便更改父组件传递过来的属性,但是可以这样修改

父组件

1 <component-a :num.sync="number">这是子组件</component-a>

子组件

 1 <template>
 2   <div>
 3     <p @click="change">子属性{{num}}</p>
 4   </div>
 5 </template>
 6 
 7 <script>
 8     export default {
 9         name: "ComponentA",
10         props: {
11           num: Number
12         },
13         methods: {
14           change(){
15             this.$emit('update:num', 10)
16           }
17         }
18     }
19 </script>

 

posted @ 2019-06-15 16:51  wlxian  阅读(6075)  评论(0编辑  收藏  举报