網站首頁 編程語言 正文
廢話不多說,上代碼
?
以下為全局腳本中:
onLaunch: function() {
if (this.globalData.videoAd) {
// onClose只監聽一次
this.globalData.videoAd.onClose(res => {
if (res.isEnded) {
// 實現子子頁面的closeAdFunction與cancelAdFunction方法
this.globalData.currentPage.closeAdFunction()
} else {
this.globalData.currentPage.cancelAdFunction()
}
})
}
},
playAd: function() {
let videoAd = this.globalData.videoAd
// 照抄的官方例子
videoAd
.show()
.then(() => {
console.log("廣告顯示成功");
})
.catch((err) => {
console.log("廣告組件出現問題", err);
// 可以手動加載一次
videoAd.load().then(() => {
console.log("手動加載成功");
// 加載成功后需要再顯示廣告
return videoAd.show();
});
});
},
globalData: {
videoAd: tt.createRewardedVideoAd({
adUnitId: '廣告ID'
}),
currentPage: Object,
}
?
?
以下為頁面腳本:
onLoad(){//定義頁面
app.globalData.currentPage = this
}
//顯示廣告
app.playAd()
//廣告監聽
closeAdFunction() {
console.log('播放結束')
},
cancelAdFunction() {
console.log('用戶取消')
},
?
原文鏈接:https://blog.csdn.net/FransicZhang/article/details/107518617
相關推薦
- 2022-06-17 C#使用讀寫鎖解決多線程并發問題_C#教程
- 2022-11-22 XML實體注入深入理解_XML示例
- 2023-10-11 MP、MybatisPlus、聯表查詢、自定義sql、Constants.WRAPPER、ew (一
- 2022-11-25 DOS窗口命令和單表簡單查詢_DOS/BAT
- 2022-03-15 ...has been blocked by CORS policy: Response to pr
- 2022-10-14 element form表單數據未雙向綁定
- 2022-07-02 python之NAN和INF值處理方式_python
- 2022-11-04 一文理解Redux及其工作原理_React
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支