继上一篇文章(传送门:微信小程序激励广告)
绑定重复的事件会产生多次重复的回调,请确认您绑定的事件是否重复,以免造成事件重复回调问题。
data(){
return{
videoAd:"",
}
},
methods:{
advert() {
this.videoAd = wx.createRewardedVideoAd({
adUnitId: "" // 申请激励广告单元ID
});
this.videoAd.onError(err => {
console.log("err", err)
})
this.videoAd.load()
.then(() => this.videoAd.show())
.catch(err => {
console.log("err", err)
this.videoAd.load()
.then(() => this.videoAd.show())
})
this.videoAd.onClose(res => {
// 关闭视频组件的回调函数
this.videoAd.offClose()
console.log("res", res);
// 用户点击了【关闭广告】按钮
if (res && res.isEnded || res === undefined) {
// 广告正常播放结束,业务逻辑
}
else {
// 播放中途退出
}
})
}},