采纳答案成功!
向帮助你的同学说点啥吧!感谢那些助人为乐的人
老师,setup中不能使用this,那我要通过什么方式获取this.$parent呢
必须保证 父组件的 props 是有值的才可以,你这里有可能父组件没有传这个 props,以下两种方式都可以
console.log(instance?.proxy?.$parent?.$props)
console.log(instance?.parent?.props)
获得父组件的 props
同学你好 可以通过 getCurrentInstance() 获得,这个内容稍微有点难度。
// 拿到一个vue 提供的内部方法
import { getCurrentInstance } from
'vue'
// 在setup 中添加如下代码
setup() {
const instance = getCurrentInstance()
// 可以通过这个 intance 上面的属性拿到一些原来 this 上面的值
console.log(instance?.proxy?.$parent)
}
老师,还是不行,我想获取parent上的props中的rules属性,但是任然是proxy对象,并且target中没有rules的值, instance?.proxy?.$parent?.$props.rules
登录后可查看更多问答,登录/注册
带你完成前后端分离复杂项目,率先掌握 vue3 造轮子技能
1.5k 2
1.3k 2
888 17
1.3k 17
1.9k 15
购课补贴联系客服咨询优惠详情
慕课网APP您的移动学习伙伴
扫描二维码关注慕课网微信公众号