Blogger Information
Blog 67
fans 0
comment 2
visits 71822
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
VUE3组件传值方式
搁浅
Original
2625 people have browsed it

Vue父子组件之间的通信

父子组件之间不能相互访问data内容

父传子

  1. // 在子组件中声明
  2. // props:['name1', 'name2' ....], 数组和对象props
  3. //用于接收传的值
  4. props: {
  5. msg:{
  6. type:String,
  7. default:'############'
  8. },
  9. MyTitle: {
  10. type:String,
  11. required:true
  12. },
  13. article: {
  14. type:Array,
  15. default:['aaaa', 'bbbb', 'cccc'],
  16. }
  17. },

在父组件中传值

  1. <my-main
  2. msg="hello"
  3. :MyTitle="msg"
  4. :article="article"
  5. >
  6. </my-main>

子传父

子组件
  1. <button @click="changenum(2)">+2</button>
  2. methods: {
  3. changenum(num) {
  4. this.$emit('mycountevent', num);
  5. },
  6. },
父组件
  1. <my-conn @mycountevent="mydemo"></my-conn>
  2. methods: {
  3. mydemo(data) {
  4. this.count += data;
  5. },
  6. },
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post