tooltip_vue2可以横竖切换添加图标

一、在 components 中新建 toolTip 文件夹并新建 toolTip.vue文件
1、写入 html 代码
<template>
	<view class="tooltip">
		<slot></slot>
		<view v-if="content || $slots.content" class="tooltip-popup" :style="initPosition">
			<view class="popup-img" :style="initImg">
				<image v-if="img" :src="img" mode="aspectFill" class="img"></image>
				{{content}}
			</view>
		</view>
	</view>
</template>
2、写入 css 代码
.tooltip {
	position: relative;

	.tooltip-popup {
		position: absolute;
		display: none;
		background-color: #666;
		border-radius: 10px;
		color: #fff;
		font-size: 12px;
		text-align: justify;
		line-height: 16px;
		padding: 10px;
		z-index: 1;
		
		.popup-img {
			
			.img {
				max-width: 30rpx;
				max-height: 30rpx;
				margin-right: 10rpx;
			}
		}
	}

	&:hover .tooltip-popup {
		display: block;
	}
}
3、写入 js 代码
export default {
	name: "toolTip",
	data() {
		return {

		};
	},
	props: {
		content: {
			type: String,
			default: ''
		},

		position: {
			type: String,
			default: 'top' // top --- 上  bottom --- 下  left --- 左  right --- 右
		},
		
		direction: {
			type: String,
			default: 'cross' // cross --- 横着   vertical --- 竖着
		},
		
		img: {
			type: String,
			default: '' // 图标 --- 可以为 base64 或者 线上链接 30rpx 以内
		},
	},
	methods: {},
	computed: {
		initPosition() {
			let style = {};
			if(this.position === 'left' && this.direction === 'cross') {
				style = {
					top: '50%',
					transform: 'translateY(-50%)',
					right: '100%',
					marginRight: '15rpx',
					width: '100%',
				}
			} else if(this.position === 'left' && this.direction === 'vertical') {
				style = {
					top: '50%',
					transform: 'translateY(-50%)',
					right: '100%',
					marginRight: '15rpx',
				}
			} else if(this.position === 'right' && this.direction === 'cross') {
				style = {
					top: '50%',
					transform: 'translateY(-50%)',
					left: '100%',
					marginLeft: '15rpx',
					width: '100%',
				}
			} else if(this.position === 'right' && this.direction === 'vertical') {
				style = {
					top: '50%',
					transform: 'translateY(-50%)',
					left: '100%',
					marginLeft: '15rpx',
				}
			} else if(this.position === 'top' && this.direction === 'cross') {
				style = {
					bottom: '100%',
					transform: 'translateX(-50%)',
					left: '50%',
					marginBottom: '15rpx',
					width: '100%',
				}
			} else if(this.position === 'top' && this.direction === 'vertical') {
				style = {
					bottom: '100%',
					transform: 'translateX(-50%)',
					left: '50%',
					marginBottom: '15rpx',
				}
			} else if(this.position === 'bottom' && this.direction === 'cross') {
				style = {
					top: '100%',
					transform: 'translateX(-50%)',
					left: '50%',
					marginTop: '15rpx',
					width: '100%',
				}
			} else if(this.position === 'bottom' && this.direction === 'vertical') {
				style = {
					top: '100%',
					transform: 'translateX(-50%)',
					left: '50%',
					marginTop: '15rpx',
				}
			}
			return style;
		},
		initImg() {
			let style = {};
			if(this.direction === 'cross') {
				style = {
					display: 'flex',
					alignItems: 'center',
				}
			} else if(this.direction === 'vertical') {
				style = {};
			}
			return style;
		}
	},
}
二、父组件调用
1、html 代码
<tool-tip content="示例文字" position="bottom" direction="cross" img="https://www.baidu.com/favicon.ico">
	<view>示例文字展示</view>
</tool-tip>
2、js代码
import toolTip from '@/components/toolTip/toolTip.vue';
export default {
	components: { toolTip },
	data() {
		return {
            
		}
	},
	methods: {

	}
}
引用 引用 引用根据这些引用内容,警告信息"warning: in the working copy of 'androidPrivacy.json', LF will be replaced by CRLF the next time Git touches it"是在提醒用户在Git操作中,回车和换行的转换将会发生。这是因为Git会在提交时对换行符进行转换以保持统一性。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [warning: in the working copy of ‘App.vue‘, LF will be replaced by CRLF the next time Git touches ...](https://blog.youkuaiyun.com/weixin_44953057/article/details/129644219)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [Git: ‘LF will be replaced by CRLF the next time Git touches it‘ 问题解决与思考](https://blog.youkuaiyun.com/Babylonxun/article/details/126598477)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [warning: in the working copy of ‘...‘, LF will be replaced by CRLF the next time Git touche](https://blog.youkuaiyun.com/weixin_55252589/article/details/129017650)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值