Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lyf911010 opened this issue Mar 13, 2018 · 3 comments
Closed

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

lyf911010 opened this issue Mar 13, 2018 · 3 comments

Comments

@lyf911010
Copy link

@lyf911010 lyf911010 commented Mar 13, 2018

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

@anchengjian
Copy link
Member

@anchengjian anchengjian commented Mar 13, 2018

建议直接用 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
Copy link

@ShenJet ShenJet commented Dec 26, 2018

遇到相同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
Copy link

@Xiaodahua Xiaodahua commented Feb 13, 2019

解决方法无效呀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants