element input 封装;避免双向数据流

子组件css

其实element的@input 并非原生的input html

而是基于原生已封装好的值this

<template>
  <div>
    <el-input :value="localValue" @input="test" size="small"></el-input>
    <div class="tag">输入多个标签时,请使用英文;区分,最多输入5个标签</div>
  </div>
</template>

<script>
  export default {
    // model: {
    //   prop: "value",
    //   event: "input"
    // },
    props: ["value"],

    data() {
      return {}
    },
    computed: {
      localValue() {
        return this.value
      }
    },
    mounted() {

    },
    methods: {

      test(a) {
        console.log(a);
        this.$emit("input", a)
      }
    }
  }
</script>

<style scoped lang='scss'>
  .tag {
    font-size: 12px;
    color: red;
  }
</style>

父组件url

<tag v-model=questionDTO.tagStr id="tag"></tag>

另外能够参考这篇博文: https://www.cnblogs.com/mark5/p/11603428.html.net

还有基于饿了么的select封装code

相关文章
相关标签/搜索