2017-07-10 9 views
1

私は国番号付きの電話番号が必要なフォームを持っています。 選択タグでは、ドロップダウン時に国名と国コードが必要ですが、選択すると国コードのみにする必要があります。それは可能ですか?国コードを選択タグvuejs2にのみ追加する方法

は、ここに私のコード

<select v-model="country" data-vv-as="Country" name="country" v-validate="'required'" :class="{'select': true, 'is-danger': errors.has('register-form.country')}" data-vv-scope="register-form"> 
    <option disabled selected>--</option> 
    <option v-for="country in countries" :value="country.id" 
    :key="country.id">{{country.name}} (+{{ country.calling_code }}) 
    </option> 
</select> 

感謝です!あなたはv-model="country"を使用し、そのようにあなたはそれがIDがないオプションの値として、国コードを渡す必要があるとv-model="selectedCountry"

  • のようなものを使用v-for="country in countries"で同じ変数名を使用してはならない

  • 答えて

    0
    1. <option v-for="country in countries" :value="country.calling_code" :key="country.id">{{country.name}} (+{{ country.calling_code }}) </option>

    関連する問題