uniapp+vue3的ifdef实现多端配置客服消息

在微信小程序预览,实现客服消息,因是个人版,不支持

button | uni-app官网 (dcloud.net.cn)

条件编译处理多端差异 | uni-app官网 (dcloud.net.cn)

uni.makePhoneCall(OBJECT) | uni-app官网 (dcloud.net.cn)

//my.vue
<template>
<view class="list">
			<view class="section">
				<view class="row">
					<view class="left">
						<uni-icons class="symbel" type="download-filled" size="20" color="#21b589"></uni-icons>
						<text>我的下载</text>
					</view>
					<view class="right">
						<text>0</text>
						<uni-icons type="right" class="arrow_right" size="15" color="#a9a9a9"></uni-icons>
					</view>
				</view>
				<view class="row">
					<view class="left">
						<uni-icons class="symbel" type="star-filled" size="20" color="#21b589"></uni-icons>
						<text>我的评分</text>
					</view>
					<view class="right">
						<text>0</text>
						<uni-icons type="right" class="arrow_right" size="15" color="#a9a9a9"></uni-icons>
					</view>
				</view>
				<view class="row">
					<view class="left">
						<uni-icons class="symbel" type="person-filled" size="20" color="#21b589"></uni-icons>
						<text>联系客服</text>
						<!-- 仅出现在 MP 平台下的代码 -->
						<!-- #ifdef MP -->
						<button open-type="contact" class="contect_with">联系客服</button>
						<!-- #endif -->
						<!-- 仅出现在 H5 平台下的代码 -->
						<!-- #ifdef H5-->
						<button @click="clickContact" class="contect_with">拨打电话</button>
						<!-- #endif -->
					</view>
					<view class="right">
						<text>0</text>
						<uni-icons class="arrow_right" type="right" size="15" color="#a9a9a9"></uni-icons>
					</view>
				</view>
				
			</view>
		</view>
</template>
<script setup>
// 拨打电话
	const clickContact=()=>{
		uni.makePhoneCall({
			phoneNumber:'13047585784'
		})
	}
</script>
<style lang="scss" scoped>
.list{
		width: 690rpx;
		margin: 0 30rpx 30rpx;
		border: 1rpx solid #eee;
		box-shadow: 0 0 30rpx rgba(0,0,0,0.05);//阴影
		border-radius: 10rpx;
		.section{
			.row{
				display: flex;
				justify-content: space-between;
				// align-items: center;
				height: 100rpx;
				border-bottom: 1px solid #eee;
				position: relative;
				&:last-child{
					border-bottom: 0 ;
				}
				.left{
					display: flex;
					align-items: center;
					color: #595959;
					.symbel{
						margin: 0 30rpx;
					}
					.contect_with{
						position: absolute;
						left: 0;
						top: 0;
						width: 100%;
						height: 100rpx;
						opacity: 0;
					}
				}
				.right{
					display: flex;
					align-items: center;
					color: #a9a9a9;
					.arrow_right{
						margin-right: 30rpx;
					}
				}
				
			}
		}
	}
</style>

UniApp是一个基于Vue.js的跨平台应用框架,它允许开发者构建一套代码,同时运行在微信小程序、H5、App多端。Vite是一个现代的前端构建工具,它强调快速启动和热更新。如果你要在UniApp项目中集成Vite,可以按照以下步骤进行配置: 1. **安装依赖** 首先确保已经全局安装了`npm`或`yarn`。然后,在 UniApp 的项目根目录下运行: ```sh npm install -D vite @dcloudio/vite-plugin-universe ``` 或者使用Yarn: ```sh yarn add -D vite @dcloudio/vite-plugin-universe ``` 2. **创建Vite配置文件** Vite 默认不会直接处理uni-app的项目结构,所以需要添加配置。在项目根目录下创建一个名为`.viterc.js`(或`.viteignore`忽略某些文件)的文件,并加入以下内容: ```javascript import { createUniPlugin } from '@dcloudio/vite-plugin-universe'; export default { plugins: [createUniPlugin()], build: { outDir: 'dist', }, }; ``` 3. **启动Vite** 使用`npm run dev` 或 `yarn dev`命令启动Vite开发服务器。 4. **迁移项目** 将现有的uni-app Vue组件迁移到Vite支持的模式。Vite默认使用ESM模块系统,所以确保所有的导入路径都是正确的。 5. **调整入口** 修改项目的`index.html`或`main.js`,将原来的`<script>`标签替换为指向Vite构建后的`bundle.js`或`chunk.xxx.js`文件。 6. **样式迁移** 如果有CSS,考虑使用Vite的预处理器如Sass、Less,或将其迁移到Webpack-style-loader配合.vue单文件组件中的<style scoped>。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值