vue 自定义input组件


<div id="app">
    <input-number v-model="val"></input-number>
    <p>{{val}}</p>
</div>
var app = new Vue({
  el: '#app',
  data: {
    val: 5
  }
})

Vue.component('input-number', {
  template: `
    <div class="input-number">
      <input type="text" v-model.number="currentValue"/>
    </div>
  `,
  data: function () {
    return {
      currentValue: this.value
    }
  },
  props: {
    value: {
      type: Number,
      default: 0
    }
  },

  watch: {
    currentValue: function (val) {this.$emit('input', val)
    }
  }
})

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM