提交 a31c4674 编写于 作者: 张磊

新增信息流广告和插屏广告示例。

上级 b3ad407b
......@@ -1803,7 +1803,26 @@
"navigationBarTitleText": "",
"backgroundColorContent": "#fffae8"
}
},
// #ifdef APP-ANDROID
{
"path" : "pages/component/ad/ad",
"style" :
{
"navigationBarTitleText" : "ad | 信息流广告",
"enablePullDownRefresh": false
}
},
{
"path" : "pages/API/create-interstitial-ad/create-interstitial-ad",
"group": "1,13,1",
"style" :
{
"navigationBarTitleText" : "createInterstitialAd | 插屏广告",
"enablePullDownRefresh": false
}
}
// #endif
],
"globalStyle": {
"pageOrientation": "portrait",
......@@ -2764,4 +2783,4 @@
]
}
]
}
\ No newline at end of file
}
<template>
<page-head title="插屏广告"></page-head>
<button :type="btnType" style="margin: 10px;" :disabled="btnDisable" @click="showAd()">{{btnText}}</button>
</template>
<script>
export default {
data() {
return {
btnText: "",
btnType: "primary",
btnDisable: false,
interstitialAd: null as InterstitialAd | null,
isAdLoadSuccess: false
}
},
onReady() {
this.loadAd()
},
methods: {
loadAd() {
if (this.btnDisable)
return
this.btnDisable = true
this.btnText = "正在加载广告"
this.btnType = "primary"
if (this.interstitialAd == null) {
this.interstitialAd = uni.createInterstitialAd({
adpid: "1111111113" //此处为测试广告位,实际开发中请在uni-ad后台申请自己的广告位后替换
})
this.interstitialAd!.onError((_) => {
this.btnType = "warn"
this.btnText = "广告加载失败,点击重试"
this.btnDisable = false
})
this.interstitialAd!.onLoad((_) => {
this.btnType = "primary"
this.btnText = "广告加载成功,点击观看"
this.btnDisable = false
this.isAdLoadSuccess = true
})
this.interstitialAd!.onClose((e) => {
this.isAdLoadSuccess = false
this.loadAd()
})
}
this.interstitialAd!.load()
},
showAd() {
if (this.isAdLoadSuccess) {
this.interstitialAd!.show()
} else {
this.loadAd()
}
}
}
}
</script>
<style>
</style>
<template>
<view>
<page-head title="信息流广告"></page-head>
<ad adpid="1111111111" style="width: 100%;" @load="loadFun" @error="errorFun"></ad>
<view v-if="tips" class="uni-center">信息流广告加载失败,请退出当前页面重试。</view>
</view>
</template>
<script>
export default {
data() {
return {
tips:false
}
},
methods: {
loadFun() {
uni.showToast({
position:"bottom",
title:"信息流广告加载成功"
})
},
errorFun() {
this.tips = true;
}
}
}
</script>
<style>
</style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册