除了支持 通用属性以外,还支持如下属性。
名称 | 类型 | 默认值 | 是否必填 | 描述 |
|---|---|---|---|---|
adunitid | string | - | 是 | 模板广告位标识,即调用ad.createTemplateAd创建模板广告时传入的广告位标识。 说明: 一个adunitid只能绑定在一个ad-view组件上。 |
除了支持 通用样式 以外,还支持如下样式。
名称 | 类型 | 默认值 | 是否必填 | 描述 |
|---|---|---|---|---|
width | length | percentage | - | 否 | 组件宽度 |
height | length | percentage | - | 否 | 组件高度 |
除了支持 通用事件 以外,还支持如下事件。
名称 | 参数 | 描述 |
|---|---|---|
click | - | UI组件的点击事件,会先触发本身的广告逻辑如跳转到落地页,启动下载等,然后会触发此事件接口。 |
error | {code:codeInteger,description:descriptionString} | 广告渲染失败。 |
render | - | 广告渲染成功。 |
close | - | 用户点击了广告的关闭按钮,您接收到此事件后需要关闭相关广告显示。 |
downloadStatus | {packageName:packageNameValue,status:statusValue,progress:progressValue} | 只有榜单类广告才出现。
|
<template>
<!-- Only one root node is allowed in template. -->
<div class="container">
<div class="item-container">
<input class="input-text" placeholder="请输入slotId" style="placeholder-color: #FF0000" onchange="setProductIdValue"></input>
<input class="input-text" placeholder="请输入广告类型" style="placeholder-color: #FF0000" onchange="setAdType"></input>
<input class="input-text" placeholder="深色模式类型" style="placeholder-color: #FF0000" onchange="setDarkMode"></input>
<input class="input-text" placeholder="请输入宽度" style="placeholder-color: #FF0000" onchange="setWidth"></input>
<input class="input-text" placeholder="请输入高度" style="placeholder-color: #FF0000" onchange="setHeight"></input>
<input class="input-text" placeholder="请输入个性化参数,0或1" style="placeholder-color: #FF0000" onchange="setPersonalizeAd"></input>
<input type="button" class="btn" value="加载模板广告" onclick="showTemplateAd()" />
<input type="button" class="btn" value="销毁广告" onclick="destroy" />
<ad-view if="{{template1.showFlag}}" class="adview" adunitid="{{template1.slotId}}" onClose="close"></ad-view>
>
</div>
</div>
</template>
<style>
.container {
flex: 1;
flex-direction: column;
}
.item-container {
margin-top: 50px;
flex-direction: column;
}
.adview {
}
.input-text {
height: 80px;
line-height: 80px;
padding-left: 30px;
padding-right: 30px;
margin-left: 30px;
margin-right: 30px;
border-top-width: 1px;
border-bottom-width: 1px;
border-color: #999999;
font-size: 30px;
color: #000000;
}
.btn {
height: 80px;
text-align: center;
border-radius: 5px;
margin-right: 60px;
margin-left: 60px;
margin-bottom: 50px;
color: #ffffff;
font-size: 30px;
background-color: #0faeff;
}
</style>
<script>
import ad from '@service.ad'
let templateAd
export default {
data: {
template1: {
slotId: "VSAtyOJNUj9",
showFlag: false,
adType: "infoCard",
darkMode: '',
width: 0,
height: 0,
personalizedAd: 0
}
},
setProductIdValue: function (e) {
this.template1.showFlag = false
this.template1.slotId = e.value
if (e.value === "") {
this.template1.slotId = "VSAtyOJNUj9"
}
},
setAdType: function (e) {
this.template1.adType = e.value
},
setDarkMode: function (e) {
this.template1.darkMode = e.value
},
setWidth: function (e) {
this.template1.width = e.value
},
setHeight: function (e) {
this.template1.height = e.value
},
setPersonalizeAd: function (e) {
this.template1.personalizedAd = e.value
},
showTemplateAd() {
console.log('start = ')
let temp = this
temp.template1.showFlag = false
templateAd = ad.createTemplateAd({
adUnitId: this.template1.slotId,
type: this.template1.adType,
darkMode: this.template1.darkMode,
width: this.template1.width,
height: this.template1.height,
personalizedAd: this.template1.personalizedAd
})
templateAd.load({
success: function (data) {
console.log('load success = ' + data)
temp.template1.showFlag = true
},
fail: function (data, code) {
console.log("load fail, code=" + code);
}
})
},
destroy() {
templateAd.destroy()
this.template1.showFlag = false
},
close() {
this.template1.showFlag = false
}
}
</script>