vue的类element的input类型组件封装

前提:题主之前只是随意的封装,项目统一ui,然后只实现了父组件拿子组件值,没有实现父组件修改子组件的值,仔细看了文档才知道用model的作用,直接上代码

Vue.component("base-input", {
  model: {
    prop: "val",
    event: "input"
  },
  props: {
    val: [String, Number]
  },
  template: `
    <input
      type="text"
      v-bind:value="val"
      @input="$emit('input', $event.target.value)"
    >
  `
});

猜你喜欢

转载自www.cnblogs.com/shuen/p/11208612.html