網(wǎng)站首頁 編程語言 正文
前言
類似
Vue
中this.$emit()
,子組件可執(zhí)行父組件的函數(shù)方法。
在小程序里,組件間通信與傳統(tǒng) Vue
有所區(qū)別。
解決方案
官方文檔:https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/events.html
其實(shí)官方文檔已介紹 this.triggerEvent
與其參數(shù),下面是更加易于理解的例子。
子組件(help):
<view bindtap="onTap">點(diǎn)我觸發(fā)父組件函數(shù)方法</view>
properties:{ text: String },
methods:{
onTap(event) {
this.triggerEvent("tapping", {
text: this.propertie.text
},{})
}
}
父組件:
<help text="ok" bind:tapping="onPost" />
onPost(event) {
console.log(event.detail.text)
console.log('當(dāng)onTap執(zhí)行時(shí)我就執(zhí)行了')
}
寫在后面
當(dāng)然,該示例只是讓您易于理解,更多寫法及注意事項(xiàng)請參考官方文檔。
原文鏈接:https://wangjiabin.blog.csdn.net/article/details/122981498
相關(guān)推薦
- 2022-05-22 C#多線程的相關(guān)操作講解_C#教程
- 2022-09-14 Go語言中序列化與反序列化示例詳解_Golang
- 2022-05-08 關(guān)于PyQt5中QtGui.QImage圖片顯示問題解析_python
- 2022-05-03 C++STL函數(shù)和排序算法的快排以及歸并排序詳解_C 語言
- 2022-03-03 【css】page-break-after 頁面打印分頁屬性
- 2022-03-19 Go?語言的?:=的具體使用_Golang
- 2022-06-22 Android開發(fā)保存QQ密碼功能_Android
- 2022-07-14 關(guān)于C#?dynamic裝箱問題_C#教程
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支