미니 프로그램을 사용하여 팝업 창 입력 구성 요소 작성

hzc
풀어 주다: 2020-06-29 10:51:15
앞으로
2683명이 탐색했습니다.

프로젝트를 작성할 때 미니 프로그램에 자체 팝업 입력 구성 요소가 없다는 것을 발견하여 직접 작성해야 했습니다.

1. 반투명 커버 레이어

커버 레이어의 스타일 및 표시 이벤트
wxml 코드:

<view class="body">
  <button bindtap=&#39;eject&#39;>弹窗</button>
</view>
<view class="model" catchtouchmove=&#39;preventTouchMove&#39; wx:if=&#39;{{showModal}}&#39;></view>
로그인 후 복사

wxss 코드:

.model{
  position: absolute;
  width: 100%;
  height: 100%;
  background: #000;
  z-index: 999;
  opacity: 0.5;
  top: 0;
  left:0;
}
로그인 후 복사

js 코드:

 /**
   * 页面的初始数据
   */
  data: {
    showModal: false,
  },

  /**
   * 控制遮盖层的显示
   */
  eject:function(){
    this.setData({
      showModal:true
    })
  }
로그인 후 복사
2.팝업 창 구현

팝업 창 스타일 및 숨겨진 이벤트
wxml 코드:

<view class="modalDlg" catchtouchmove=&#39;preventTouchMove&#39; wx:if=&#39;{{showModal}}&#39;>
  <view class=&#39;windowRow&#39;>
    <text class=&#39;userTitle&#39;>标题
  </text>
    <view class=&#39;back&#39; bindtap=&#39;back&#39;>
      返回
    </view>
  </view>
  <view class=&#39;wishName&#39;>
    <input bindinput=&#39;wish_put&#39; placeholder=&#39;请输入内容&#39; class=&#39;wish_put&#39;></input>
  </view>
  <view class=&#39;wishbnt&#39;>
    <button class=&#39;wishbnt_bt&#39; bindtap=&#39;ok&#39;>确定</button>
  </view>
</view>
로그인 후 복사

wxss 코드:

.modalDlg{
  width: 70%;
  position: fixed;
  top:350rpx;
  left: 0;
  right: 0;
  z-index: 9999;
  margin: 0 auto;
  background-color: #fff;
  border-radius: 10rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.windowRow{
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  height: 110rpx;
  width: 100%;
}

.back{
  text-align: center;
  color: #f7a6a2;
  font-size: 30rpx;
  margin: 30rpx;
}

.userTitle{
  font-size: 30rpx;
  color: #666;
  margin: 30rpx;
}

.wishName{
  width: 100%;
  justify-content: center;
  flex-direction: row;
  display: flex;
  margin-bottom: 30rpx;
}

.wish_put{
  width: 80%;
  border: 1px solid;
  border-radius: 10rpx;
  padding-left: 10rpx;
}

.wishbnt{
  width: 100%;
  font-size: 30rpx;
  margin-bottom: 30rpx;
}


.wishbnt_bt{
  width: 50%;
  background-color: #f7a6a2;
  color: #fbf1e8;
  font-size: 30rpx;
  border: 0;
}
로그인 후 복사

js 코드:

/**
   * 页面的初始数据
   */
  data: {
    showModal: false,
    textV:''
  },

  /**
   * 控制显示
   */
  eject:function(){
    this.setData({
      showModal:true
    })
  },

  /**
   * 点击返回按钮隐藏
   */
  back:function(){
    this.setData({
      showModal:false
    })
  },

  /**
   * 获取input输入值
   */
  wish_put:function(e){
    this.setData({
      textV:e.detail.value
    })
  },

  /**
   * 点击确定按钮获取input值并且关闭弹窗
   */
  ok:function(){
    console.log(this.data.textV)
    this.setData({
      showModal:false
    })
  }
로그인 후 복사
3. 전체 코드

마지막으로 전체 코드를 제시합니다. 조금 장황하지만 최대한 자세히 설명하고 싶습니다.
wxml 코드:

<view class="body">
  <button bindtap=&#39;eject&#39;>弹窗</button>
</view>
<view class="model" catchtouchmove=&#39;preventTouchMove&#39; wx:if=&#39;{{showModal}}&#39;></view>
<view class="modalDlg" catchtouchmove=&#39;preventTouchMove&#39; wx:if=&#39;{{showModal}}&#39;>
  <view class=&#39;windowRow&#39;>
    <text class=&#39;userTitle&#39;>标题
  </text>
    <view class=&#39;back&#39; bindtap=&#39;back&#39;>
      返回
    </view>
  </view>
  <view class=&#39;wishName&#39;>
    <input bindinput=&#39;wish_put&#39; placeholder=&#39;请输入内容&#39; class=&#39;wish_put&#39;></input>
  </view>
  <view class=&#39;wishbnt&#39;>
    <button class=&#39;wishbnt_bt&#39; bindtap=&#39;ok&#39;>确定</button>
  </view>
</view>
로그인 후 복사

wxss 코드:

.body{
  width: 100%;
  height: 100%;
  background-color: #fff;
  position: fixed;
  display: flex;
}

.body button{
  height: 100rpx;
}

.model{
  position: absolute;
  width: 100%;
  height: 100%;
  background: #000;
  z-index: 999;
  opacity: 0.5;
  top: 0;
  left:0;
}

.modalDlg{
  width: 70%;
  position: fixed;
  top:350rpx;
  left: 0;
  right: 0;
  z-index: 9999;
  margin: 0 auto;
  background-color: #fff;
  border-radius: 10rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.windowRow{
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  height: 110rpx;
  width: 100%;
}

.back{
  text-align: center;
  color: #f7a6a2;
  font-size: 30rpx;
  margin: 30rpx;
}

.userTitle{
  font-size: 30rpx;
  color: #666;
  margin: 30rpx;
}

.wishName{
  width: 100%;
  justify-content: center;
  flex-direction: row;
  display: flex;
  margin-bottom: 30rpx;
}

.wish_put{
  width: 80%;
  border: 1px solid;
  border-radius: 10rpx;
  padding-left: 10rpx;
}

.wishbnt{
  width: 100%;
  font-size: 30rpx;
  margin-bottom: 30rpx;
}


.wishbnt_bt{
  width: 50%;
  background-color: #f7a6a2;
  color: #fbf1e8;
  font-size: 30rpx;
  border: 0;
}
로그인 후 복사

js 코드:

Page({

  /**
   * 页面的初始数据
   */
  data: {
    showModal: false,
    textV:''
  },

  /**
   * 控制显示
   */
  eject:function(){
    this.setData({
      showModal:true
    })
  },

  /**
   * 点击返回按钮隐藏
   */
  back:function(){
    this.setData({
      showModal:false
    })
  },

  /**
   * 获取input输入值
   */
  wish_put:function(e){
    this.setData({
      textV:e.detail.value
    })
  },

  /**
   * 点击确定按钮获取input值并且关闭弹窗
   */
  ok:function(){
    console.log(this.data.textV)
    this.setData({
      showModal:false
    })
  }
})
로그인 후 복사

추천 튜토리얼: "WeChat Mini Program"

위 내용은 미니 프로그램을 사용하여 팝업 창 입력 구성 요소 작성의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:jianshu.com
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!