Vux: Address组件,设置初始值会报错误

Created on 27 Jul 2016  ·  7Comments  ·  Source: airyland/vux

给address设置初始值会报错误:
Uncaught TypeError: Cannot read property 'name' of undefined value2name.js?ca82:11
设置的初始值为:['黑龙江省','哈尔滨市','道理区']
值是之前用address选取了,保存下来的。

version:0.1.2

code:

<template>
  <div class="view">
    <bar-header title="收货人编辑"></bar-header>
    <div class="scroll-content overflow-scroll has-header">
      <consignee-form @on-submit="" :form-model="consignee"></consignee-form>
    </div>
  </div>
</template>
<script type="text/babel">
  import BaseView from './BaseView.vue'
  import Consignee from '../services/Consignee'


  export default BaseView.extend({
    data(){
      return {
        consignee:{}
      }
    },
    ready(){
      debugger;
      let consignee=this.getConsigneeById(this.$route.params.id);
      consignee.address=[consignee.province,consignee.city,consignee.area];
      this.consignee=consignee;
    },
    methods: {
      someFn(){

      }
    }
  });
</script>
<template>
  <form @submit.prevent="onFormSubmit">
    <group>
      <x-input title="收货人" :value.sync="formModel.name"></x-input>
      <x-input title="电话" :value.sync="formModel.mobile"></x-input>
      <address title="省市区" :list="list" raw-value :value.sync="formModel.address" placeholder="请选择"></address>
      <x-textarea placeholder="详细地址" :min="2" :value.sync="formModel.detail"></x-textarea>
    </group>

    <group>
      <div class="padding-horizontal">
        <button type="submit" class="button button-assertive button-block">{{submitText}}</button>
      </div>
    </group>
  </form>
</template>
<script type="text/babel">
  import regions from 'vux/src/components/address/list.json'
  import Base from '../Base.vue'
  export default Base.extend({
    data(){
      return {
        list: regions
      }
    },
    props: {
      formModel:{
        type:Object,
        default(){
          return {};
        }
      },
      submitText:{
        type:String,
        default:'保存'
      }
    },
    methods: {
      onFormSubmit(e){
        this.$emit('on-submit',this.formModel,e);
      }
    }
  });
</script>

Most helpful comment

@airyland 我也是忙,活很多,等过段时间闲了,也许可以帮上忙 :smiley:

All 7 comments

另外还有两个问题:

  1. 我在文档上看到了raw-value,这个属性,但并没有说明有什么用。
  2. 选取的位置返回是value,可以返回name吗

raw-value即指定初始化时的值是文字值,内部会将文字值转换为数字,组件已经渲染后必须用数字id来设定。

那这个错误就是由它引起的咯?

因为你并不是直接赋值,而是在组件渲染后再赋文字值,因此会报错。

@airyland 其实我希望文档能说明白点,现在连参数说明都不全,必须要去看源码才知道怎么做,很痛苦啊 :sob:

你可以帮忙完善文档。。最近比较忙,issue也比较多,处理不过来。

@airyland 我也是忙,活很多,等过段时间闲了,也许可以帮上忙 :smiley:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hao-li picture hao-li  ·  3Comments

felixjing picture felixjing  ·  4Comments

prettybot picture prettybot  ·  3Comments

RenShine picture RenShine  ·  4Comments

skyshirt picture skyshirt  ·  4Comments