Vue js apply filter on v-model in an input field

前端 未结 7 1681
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-03 22:37

Hope someone can help me! I have made a directive wrapping the Jasny Bootstrap Plugin more specifically the input-mask thing and everything goes well!

Now I have made a

相关标签:
7条回答
  • 2021-02-03 23:08

    I've found that I can filter input using the ordinary component v-bind:value / v-on:input dance without resorting to data or watch clauses if I just call $forceUpdate() after emitting the filtered value:

    The Vue component:

    {
      props: ['value'],
      methods: {
        mEmit: function(EVT) {
          const VAL      = EVT.target.value;
          var   FILTERED = myFilterFunction(VAL);
          this.$emit('input', FILTERED);
          this.$forceUpdate();
        }
      }
    }
    

    The component HTML (data is filtered as it is entered):

      <input type="text" v-bind:value="value" v-on:input="mEmit($event)" />
    

    Using the component:

    <my-component v-model="myDataVar"></my-component>
    
    0 讨论(0)
提交回复
热议问题