JiFu's Wiki JiFu's Wiki
首页
  • HTML
  • JavaScript
  • NodeJS
  • Vuejs
  • 微信小程序
  • Python
  • 数据库
  • 中间件
  • 算法
  • 软件工程
  • Wordpress
  • iOS开发
  • Android开发
  • Linux
  • Windows
  • MacOS
  • Docker
  • Vim
  • VSCode
  • Office
  • 其他
  • Photoshop
  • Sketch
  • Mac
  • 游戏
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
首页
  • HTML
  • JavaScript
  • NodeJS
  • Vuejs
  • 微信小程序
  • Python
  • 数据库
  • 中间件
  • 算法
  • 软件工程
  • Wordpress
  • iOS开发
  • Android开发
  • Linux
  • Windows
  • MacOS
  • Docker
  • Vim
  • VSCode
  • Office
  • 其他
  • Photoshop
  • Sketch
  • Mac
  • 游戏
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • HTML

  • JavaScript

  • Nodejs

  • Vuejs

    • Troubleshooting

      • 关闭Eslint中的规则 no-unused-vars
      • 禁止手机浏览器zoomin
    • VueJS介绍
    • Vuejs父组件访问子组件属性
      • 1. 子组件定义ref属性
      • 2. 父组件访问 $refs 属性
      • 1. 父组件定义components
      • 2. 子组件定义props
      • 3. 子组件使用调用方法
      • 1. 父组件定义components
      • 2. 父组件定义provide
      • 3. 子组件定义inject
      • 4. 子组件使用调用方法
    • 一文带你掌握 Vue3 新特性
    • Vue项目setup流程
  • 微信小程序

  • 前端技术
  • Vuejs
JiFu
2023-10-18
目录

Vuejs父组件访问子组件属性

# 父组件访问子组件属性/方法

# 1. 子组件定义ref属性

<SalesOrderPaymentCom
	ref="SalesOrderPaymentCom"
>
</SalesOrderPaymentCom>
1
2
3
4

# 2. 父组件访问 $refs 属性

# 访问子组件属性

// this.$refs.ref名称.子组件属性名
this.$refs.SalesOrderPaymentCom.paymentList
1
2

# 访问子组件方法

// this.$refs.ref名称.子组件方法名
this.$refs.SalesOrderPaymentCom.showAlert()
1
2

# 子组件访问父组件属性

# 1. 父组件定义components

components: {
    Autocomplete
}
1
2
3

# 2. 子组件定义props

// 将total_paid, amount_to_pay引入
props: ["total_paid", "amount_to_pay"],
1
2

# 3. 子组件使用调用方法

// 与本地方法调用方式相同
console.log(this.total_paid)
console.log(this.amount_to_pay)
1
2
3

# 子组件访问父组件方法

# 1. 父组件定义components

components: {
    Autocomplete
}
1
2
3

# 2. 父组件定义provide

// 将父组件的paymentAmountChange()的方法,提供为paymentAmountChange
provide() {
  return {
    paymentAmountChange: this.paymentAmountChange,
  };
},
1
2
3
4
5
6

# 3. 子组件定义inject

// 将paymentAmountChange引入
inject: ["paymentAmountChange"],
1
2

# 4. 子组件使用调用方法

// 与本地方法调用方式相同
this.paymentAmountChange(record)
1
2
上次更新: 2023/10/18, 08:38:42
VueJS介绍
一文带你掌握 Vue3 新特性

← VueJS介绍 一文带你掌握 Vue3 新特性→

最近更新
01
Wordpress数据库优化
06-16
02
项目标准化gitignore
06-10
03
WPS快捷键
05-21
更多文章>
Theme by Vdoing | Copyright © 2019-2025 Ji Fu | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式