子组件给父组件传递信息,首先父组件要给子组件一个函数,然后子组件在调用这个函数 通过父组件给子组件传递函数类型的props实现:子给父传递数据 例子: 我们定义一个函数:getSchoolName App.vue: <template> ... <LqjSchool :getSchoolName="getSchoolName"></LqjSchool> <StudentLqj></StudentLqj> </template>...
在父组件的模板中,将该方法作为props传递给子组件: 使用v-bind(或简写为:)语法将parentMethod方法绑定到子组件的props上。 在子组件中,声明接收的props: 在子组件中,使用defineProps声明一个props来接收从父组件传递过来的方法。指定该props的类型为Function,并标记为必需(如果适用)。 vue <!-- ChildComponent...
<template>通过父组件给子组件绑定一个自定义事件实现:子给父传递数据<StudentLqj v-on:atlqj="getStudentName"></StudentLqj>//或者//<StudentLqj @atlqj="getStudentName"></StudentLqj>//如果像点击之点击一次后不让用户再次点击://<StudentLqj @atlqj.once="getStudentName"></StudentLqj></template> ...