input-price.vue 1.07 KB
<template>
 <div class="input-wrapper">
   <div class="price-symbol">¥</div>
   <input ref="input" :value="value" class="tip" type="text" placeholder="定价需以9结尾,例如¥1299" @blur="onBlur"
          @change="onChange"></input>
 </div>
</template>

<script>
export default {
  name: 'InputPrice',
  props: {
    value: {
      type: [Number, String],
      default: ''
    }
  },
  data() {
    return {
      val: this.value
    };
  },
  methods: {
    onBlur() {
      this.$emit('on-blur');
    },
    onChange() {
      this.$emit('input', this.$refs.input.value);
    }
  },
  watch: {
    value(newVal) {
      this.val = newVal;
    }
  }
};
</script>

<style lang="scss" scoped>
.input-wrapper {
  display: flex;
  position: relative;
  height: 100px;
  background: #f5f5f5;
}

.price-symbol {
  width: 40px;
  margin-left: 20px;
  margin-right: 10px;
  font-size: 40px;
  font-weight: bolder;
  line-height: 100px;
}

.tip {
  flex: 1;
  font-size: 28px;
  line-height: 100px;
  background: #f5f5f5;
}

::placeholder {
  color: #ccc;
  opacity: 1; /* Firefox */
}

</style>