vant-weapp, mpvue, applet project: in addition to the function to get the event e, like to add parameters

surroundings

  • IU: Staying weapp
  • Applets
  • mpvue

Problem Description

vant-weappThere is a component ActionSheet 上拉菜单, you need to use their selectmethod to get users have to click on the selected value, the value of his event.detail, I need to get this value

UI effects

UI effects

html

<!-- 性别弹窗 -->
<van-action-sheet :show="sex.show" :actions="sex.actions" :cancel-text="sex.cancel" @cancel='myCancel("sex")' @select="sexSelect" />

Note that@select="sexSelect"

Configuration

sex: {
  show: false,
  cancel: '取消',
  current: '',
  actions: [
    {
      name: '男'
    },
    {
      name: '女'
    }
  ]
}

function

// 性别弹窗里面
sexSelect: function (e) {
  console.log(e)
  this.sex.show = false
  this.sex.current = e.mp.detail.name
},

e.mp.detail.nameUsers will be able to get a drop-down selection Found

Improved demand

I do not just want to get user input, I would like to carry other parameters, fill the pit for a long time, only to have to find a method, pay attention to this @select="sexSelect($event,'name')"side too $event, there must be $, otherwise not get, error

<!-- 性别弹窗 -->
<van-action-sheet :show="sex.show" :actions="sex.actions" :cancel-text="sex.cancel" @cancel='myCancel("sex")' @select="sexSelect($event,'name')" />

js

 // 性别弹窗里面
 sexSelect: function (e, name) {
   console.log(e)
   console.log(name)
   this.sex.show = false
   this.sex.current = e.mp.detail.name
 },

So I can get the user to select the parameter name and value have to carry

The above parameters have to carry another implementation

 <!-- 性别弹窗 -->
 <van-action-sheet data-index="250" :show="sex.show" :actions="sex.actions" :cancel-text="sex.cancel" @cancel='myCancel("sex")' @select="sexSelect" />

Note: data-index="250"If the binding was a property name, and needs :, for example :data-index="myValue", indexcan be changed to another name

Here Insert Picture Description

Published 108 original articles · won praise 29 · views 110 000 +

Guess you like

Origin blog.csdn.net/Gabriel_wei/article/details/98042857