Skip to content

表单元素radio value无法绑定 #66

Closed
@lyf911010

Description

@lyf911010

在使用input type=radio时候,编译之后,radio标签中的value值一直为空,不知道如何绑定

Activity

anchengjian

anchengjian commented on Mar 13, 2018

@anchengjian
Member

建议直接用 radio-group :

<template>
  <div>
    <radio-group class="radio-group" @change="radioChange">
      <label class="radio" v-for="(item, index) in items" :key="item.name">
        <radio :value="item.name" :checked="item.checked"/> {{item.value}}
      </label>
    </radio-group>
  </div>
</template>

<script>
export default {
  data () {
    return {
      items: [
        {name: 'USA', value: '美国'},
        {name: 'CHN', value: '中国', checked: 'true'},
        {name: 'BRA', value: '巴西'},
        {name: 'JPN', value: '日本'},
        {name: 'ENG', value: '英国'},
        {name: 'TUR', value: '法国'}
      ]
    }
  },
  methods: {
    radioChange (e) {
      console.log('radio发生change事件,携带value值为:', e.target.value)
    }
  }
}

</script>

参见微信文档: https://mp.weixin.qq.com/debug/wxadoc/dev/component/radio.html

ShenJet

ShenJet commented on Dec 26, 2018

@ShenJet

遇到相同bug,
最终摸索出的解决方法是:

<radio :value="item.name" :checked="item.checked"/> {{item.value}}

改写成:
<radio :value="item.name" :checked="item.checked"> {{item.value}} </radio>

估计原因:mpvue认为原生单标签组件radio没有闭合,认为同组中的所有radio都是同一个标签,所以会造成点击后面的label,但是总是第一个radio被勾选的bug.
仅是个人猜测,没有去深究

Xiaodahua

Xiaodahua commented on Feb 13, 2019

@Xiaodahua

解决方法无效呀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @anchengjian@lyf911010@ShenJet@Xiaodahua

        Issue actions

          表单元素radio value无法绑定 · Issue #66 · Meituan-Dianping/mpvue