area.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <template>
  2. <div class="input-area">
  3. <el-select ref="select" v-model="code" @change="change" slot="prepend" placeholder="请选择">
  4. <div slot="prefix" class="code" @click="$refs.select.focus()">{{code}}</div>
  5. <el-option v-for="(area, index) of areas" :key="index" :label="area.name" :value="area.pre"></el-option>
  6. </el-select>
  7. <el-input v-model="mobile" @change="change" placeholder="请输入手机号"></el-input>
  8. </div>
  9. </template>
  10. <script>
  11. export default {
  12. data() {
  13. return {
  14. areas: [],
  15. code: '+86',
  16. mobile: '',
  17. }
  18. },
  19. computed: {
  20. fullMobile() {
  21. return `${this.code}-${this.mobile}`
  22. }
  23. },
  24. mounted() {
  25. this.getAreas()
  26. },
  27. methods: {
  28. async getAreas() {
  29. let res = await this.$axios.$post('/api/user/get_mobile_pre_arr')
  30. if(res) {
  31. this.areas = res.data.mobilePreArr
  32. }
  33. },
  34. change() {
  35. this.$emit('change', this.fullMobile)
  36. },
  37. }
  38. }
  39. </script>
  40. <style scoped>
  41. .input-area {
  42. position: relative;
  43. display: flex;
  44. align-items: center;
  45. }
  46. .el-select {
  47. width: 120px;
  48. }
  49. .code {
  50. position: absolute;
  51. top: 2px;
  52. left: 10px;
  53. width: 50px;
  54. line-height: 36px;
  55. background: white;
  56. cursor: pointer;
  57. text-align: center;
  58. color: #333;
  59. }
  60. </style>