vue3中的父子组件传值

一:子组件调用父组件的方法

1.父组件




2.子组件




接收父组件传来的值:(四种方式)

// 方式一
const props = defineProps(["count"]);

// 方式二:可以设置传来值的类型
const props = defineProps({
  count: Number,
})

// 方式三:可以设置传来值的类型、默认值
const props = defineProps({
  count: {
    type: Number,
    default: 0
  }
})

// 方式四:可以设置传来值的多种类型
const props = defineProps({
  count: [Number, String],
})

二:父组件调用子组件的方法

1.父组件




2.子组件




关于vue3的一些用法:
Vue 3.x新特性总结
[保姆级] Vue3 开发文档

你可能感兴趣的:(vue.js,javascript,前端)