使用uni-popup结合picker-view踩坑笔记

注意:使用picker-view时要给他加上以下样式。不给高度他不显示,高度可以随意更改

picker-view-column {
        height: 600rpx;
        text-align: center;

        view {
            line-height: 34px;
        }
    }

同时使用uni.popup组件时想叫顶部出现圆角必须将uni-popup标签上的背景色改成background-color="rgba(0,0,0,0)" ,然后添加以下样式即可

.popup-content {
		border-top-right-radius: 20rpx;
		border-top-left-radius: 20rpx;
		background-color: #eee;
	}

但是可能出现弹出层与底部有距离,解决办法在下:

找到uniapp源码,在标签上添加任意类名,在所需要的组件添加以下样式即可

    const show = ref(false)  //这个变量和下方change函数是为了解决打开弹出层滑动时禁止窗口滑动
	const type = ref('');
	const popup = ref(null);
	const date = new Date();
	const years = ref([]);
	const year = ref(date.getFullYear());
	const months = ref([]);
	const month = ref(date.getMonth() + 1);
	const day = ref(date.getDate());

	// 初始化年份和月份数组
	for (let i = 1990; i <= date.getFullYear(); i++) {
		years.value.push(i);
	}
	for (let i = 1; i <= 12; i++) {
		months.value.push(i);
	}

	const value = ref([9999, month.value - 1, day.value - 1]);
	const visible = ref(true);
	const indicatorStyle = `height: 50px;`;
	const currentTab = ref('all');
	const details = ref([]);
    //---------------------------------与第一行解释对应
	const change = (e) => {
		show.value = e.show
	}
    //---------------------------------
    //关闭弹出层
	const closeEdit = () => {
		popup.value.close()
	}
    //确定执行接口操作就好
	const doSave = () => {

	}
    const bindChange = (e) => {
		const val = e.detail.value;
		// year.value = years.value[val[0]];
		// month.value = months.value[val[1]];
        //------------------------------------------------在这里可以拿到选择的年月
		console.log(years.value[val[0]], months.value[val[1]]);
	};
    //----------------------------------------------------这里决定弹出层从那出现
	const toggle = (position) => {
		type.value = position;
		popup.value.open(position);
	};
//与上方js第一行对应解释
<page-meta :page-style="'overflow:'+(show?'hidden':'visible')"></page-meta>
<uni-popup ref="popup" background-color="rgba(0,0,0,0)" safe-area="false" @change="change">
			<view class="popup-content" :class="{ 'popup-height': type === 'left' || type === 'right' }">
				<view class="popup_head">
					<text class="cancel" style="color: #ccc;" @click="closeEdit">取消</text>
					<text class="cancel">选择年月</text>
					<text class="saveMsg" style="color: #299F95;" @click="doSave">确定</text>
				</view>
				<picker-view v-if="visible" :indicator-style="indicatorStyle" :value="value" @change="bindChange"
					class="picker-view">
					<picker-view-column>
						<view class="item" v-for="(item, index) in years" :key="index">{{ item }}年</view>
					</picker-view-column>
					<picker-view-column>
						<view class="item" v-for="(item, index) in months" :key="index">{{ item }}月</view>
					</picker-view-column>
				</picker-view>
			</view>
		</uni-popup>

  • 13
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
uni.showModal是uni-app框架中用于显示模态对话框的API,而uni-popup是一个常用的弹窗组件库。在uni.showModal的success回调函数中使用uni-popup可以实现更加丰富的弹窗效果。 要在uni.showModal的success回调中使用uni-popup,首先需要在项目中引入uni-popup组件库。可以通过npm安装或者直接下载组件库的源码,并在需要使用的页面中引入。 然后,在uni.showModal的success回调函数中,可以通过uni-popup提供的API来创建和显示弹窗。具体的步骤如下: 1. 引入uni-popup组件库: ```javascript import uniPopup from '@/components/uni-popup/uni-popup.vue'; ``` 2. 在页面的components属性中注册uni-popup组件: ```javascript components: { uniPopup }, ``` 3. 在success回调函数中创建并显示弹窗: ```javascript uni.showModal({ title: '提示', content: '这是一个模态对话框', success: function(res) { if (res.confirm) { // 用户点击了确定按钮 // 创建并显示uni-popup弹窗 this.$refs.popup.open(); } else if (res.cancel) { // 用户点击了取消按钮 } } }); ``` 4. 在页面的template中添加uni-popup组件的标签,并设置相应的属性和事件: ```html <uni-popup ref="popup" @close="onPopupClose"> <!-- 弹窗内容 --> </uni-popup> ``` 5. 在页面的methods中定义onPopupClose方法,用于处理弹窗关闭事件: ```javascript methods: { onPopupClose() { // 弹窗关闭时的逻辑处理 } } ``` 通过以上步骤,就可以在uni.showModal的success回调中使用uni-popup来实现弹窗效果了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值