admin管理员组

文章数量:1614276

随着技术的发展,开发的复杂度也越来越高,传统开发方式将一个系统做成了整块应用,经常出现的情况就是一个小小的改动或者一个小功能的增加可能会引起整体逻辑的修改,造成牵一发而动全身。通过组件化开发,可以有效实现单独开发,单独维护,而且他们之间可以随意的进行组合。大大提升开发效率低,降低维护成本。

 

组件化对于任何一个业务场景复杂的前端应用以及经过多次迭代之后的产品来说都是必经之路。组件化要做的不仅仅是表面上看到的模块拆分解耦,其背后还有很多工作来支撑组件化的进行,例如结合业务特性的模块拆分策略、模块间的交互方式和构建系统等等 。

 

本文给大家介绍的一款组件是:

前端vue uni-app检测手机系统是iOS还是android(可实现根据手机系统跳转App下载链接);

效果图如下: 

 

实现代码如下:

# 使用方法

#### HTML代码部分

```html

<template>

<view class="content">

<image class="logo" src="@/static/img/appIcon.png" mode="aspectFit"></image>

<view class="text-area">

<text class="title">{{title}}</text>

</view>

</view>

</template>

```

#### JS代码 (引入组件 填充数据)

```javascript

<script>

export default {

data() {

return {

title: '检测手机系统iOS/android系统跳转链接下载App'

}

},

mounted() {

},

onLoad() {

let urlStr = '';

if (this.detect() === 'ios') {

//对IOS系统的移动端页面做点什么

urlStr =

'https://apps.apple/cn/app/'

location.href = urlStr;

this.title = "当前手机系统: iOS";

} else if (this.detect() === 'android') {

urlStr = 'https://appgallery1.huawei/#/app/';

location.href = urlStr;

this.title = "当前手机系统: android";

} else {

}

},

methods: {

detect() {

let equipmentType = "";

let agent = navigator.userAgent.toLowerCase();

let android = agent.indexOf("android");

let iphone = agent.indexOf("iphone");

let ipad = agent.indexOf("ipad");

if (android != -1) {

equipmentType = "android";

}

if (iphone != -1 || ipad != -1) {

equipmentType = "ios";

}

return equipmentType;

}

}

}

</script>

```

#### CSS

```CSS

<style>

.content {

display: flex;

flex-direction: column;

align-items: center;

justify-content: center;

}

.logo {

height: 200rpx;

width: 200rpx;

margin-top: 200rpx;

margin-bottom: 40rpx;

}

.title {

font-size: 36rpx;

color: #333333;

}

</style>

```

阅读全文下载完整代码请关注微信公众号: 前端组件开发

 

 

 

 

本文标签: 系统手机跳转下载链接app