This article mainly introduces in detail the method of adding open-screen advertisements or splash-screen advertisements to the vue2 mobile APP project. It has a certain reference value. Interested friends can refer to it
General projects , some will add opening screen ads or splash screen ads when starting. We do this through positioning in index.html. As follows:
<style media="screen"> #entry { width: 100%; height: 100%; z-index: 200; position: relative; } #entryAdv { display: none; } #entryTim { position: fixed; width: 2.2rem; line-height: 0.68rem; font-size: 0.32rem; z-index: 400; text-align: center; border-radius: 2rem; top: 0.5rem; right: 0.5rem; border: 1px solid #ccc; } </style> <body> <!-- 开屏广告 --> <section class="adv" id="entryAdv"> <img id="entry" alt="How to add open-screen advertisements to mobile APP projects in vue2" > <p id="entryTim"></p> </section> <!-- 入口元素 --> <section id="app"></section> </body>
Then we need to write a separate js file, which is in the same directory as main.js. The specific code is as follows:
import api from './fetch/api' import store from './store/index' // 修改开屏广告图片尺寸 let advWidth = document.documentElement.clientWidth; let advHeight = document.documentElement.clientHeight; let entryEl = document.getElementById('entry'); entryEl.style.widht = advWidth + 'px'; entryEl.style.height = advHeight + 'px'; let queryURL = window.location.href.split('?')[1]; // 判断是否为分享页面 if (queryURL) { let queryArr = queryURL.split('&'); let query = {}; for (let i = 0; i < queryArr.length; i++) { query[queryArr[i].split('=')[0]] = queryArr[i].split('=')[1] } if (Number(query.showTitle)) { // 分享页面中 H5入口(我们项目中做了分享功能,若是从原生APP分享进入H5页面的,也需要加开屏广告) api.commonApi('后台接口', '传参数') .then(res => { let keyArr = []; for (let key in res.data) { keyArr.push(key); } if (keyArr.length == 0) { return; } openAdv(res); }); } else { // 分享页面中 原生入口 // 查看query中是否带有token,进行登录判断并将token存入vuex if (query.TOKEN != '' && query.TOKEN != 'null') { store.dispatch('storeToken', query.TOKEN); } } } else { // 不是分享页面的入口 api.commonApi('后台接口', '传参数') .then(res => { let keyArr = [] for (let key in res.data) { keyArr.push(key); } if (keyArr.length == 0) { return; } openAdv(res); }); } function openAdv(res) { entryAdv.style.display = 'block'; document.body.style.overflowY = 'hidden'; // 阻止滑动执行 document.body.ontouchmove = function(ev) { ev.preventDefault(); }; let list = res.data.retList; if (list && list.length == 0) { entryAdv.style.display = 'none'; document.body.style.overflow = 'auto'; document.body.ontouchmove = function(ev) { ev.stopPropagation(); }; } let time = (res.data.SPJG || 5000) / 1000; // let time = res.data.SPJG; let ADV_list = []; let BCcontextPathSrc = store.state.common.BCcontextPathSrc; switch (res.data.ADV_TYPE) { // 开屏直接跳过 case '1': { let ImgList = []; for (let i = 0; i < list.length; i++) { ImgList.push(BCcontextPathSrc + res.data.retList[i].ADV_IMG_URL); ADV_list.push(res.data.retList[i].ADV_URL); } let count_down = time / list.length; let ImgNum = 0; let timer = setInterval(() => { switch (ImgList.length) { case 1: break; case 2: { if (time % 3 == 0) { ImgNum++; } } break; case 3: { if (time % 2 == 0) { ImgNum++; } } break; case 4: { if (time % 1 == 0) { if (ImgNum > ImgList.length - 2) break; ImgNum++; } } break; default: { if (time % 1 == 0) { if (ImgNum > ImgList.length - 2) break; ImgNum++; } } break; } if (time <= 0) { clearInterval(timer); entryAdv.style.display = 'none'; document.body.style.overflowY = 'auto'; document.body.ontouchmove = function(ev) { ev.stopPropagation(); }; } entry.src = ImgList[ImgNum]; entryTim.innerHTML = '跳过 ' + time + 's'; entry.addEventListener('click', function() { window.location.href = ADV_list[ImgNum]; }, false); time--; }, 1000); entryTim.addEventListener('click', function(ev) { ev.preventDefault(); clearInterval(timer); entryAdv.style.display = 'none'; document.body.style.overflowY = 'auto'; document.body.ontouchmove = function(ev) { ev.stopPropagation(); }; }, false); } break; // 闪屏广告 case '2': 同上开屏广告,可根据贵公司要求来更改 } }; setTimeout(() => { require('./main.js'); }, 300)
The above is what I compiled for everyone. I hope that in the future It will be helpful to everyone.
Related articles:
How to implement the drag and drop function in AngularJS
How to implement a chat room using socket.io
How to use nodejs to operate the fill, delete, modify and query module of mongodb
How to use js to implement reassignment
In JS How to implement verification code countdown
The above is the detailed content of How to add open-screen advertisements to mobile APP projects in vue2. For more information, please follow other related articles on the PHP Chinese website!

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version
God-level code editing software (SublimeText3)