最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Use the mask Vue 3 - Stack Overflow

programmeradmin5浏览0评论

I have a phone mask. More precisely, an error instead of a mask. I really can't figure out why the error occurs because it is pletely uninformative!!!

<template>
  <input type="text" v-model="value" v-mask="'#-#-#'" />
</template>

<script>
import { ref, defineComponent } from "vue";

export default defineComponent({
  setup() {
    const value = ref("");

    return { value };
  },
  watch: {
    value(n) {
      this.$emit("input", n);
    },
  },
});
</script>

=/src/App.vue

If you remove the v-mask directive, then everything works as it should. How can I solve the error??

Thank you!

I have a phone mask. More precisely, an error instead of a mask. I really can't figure out why the error occurs because it is pletely uninformative!!!

<template>
  <input type="text" v-model="value" v-mask="'#-#-#'" />
</template>

<script>
import { ref, defineComponent } from "vue";

export default defineComponent({
  setup() {
    const value = ref("");

    return { value };
  },
  watch: {
    value(n) {
      this.$emit("input", n);
    },
  },
});
</script>

https://codesandbox.io/s/musing-resonance-dyl63c?file=/src/App.vue

If you remove the v-mask directive, then everything works as it should. How can I solve the error??

Thank you!

Share Improve this question asked Sep 30, 2022 at 18:51 OleksandrOleksandr 4751 gold badge9 silver badges20 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 1

Try to register it locally, it should work :

<template>
  <input type="text" v-model="value" v-maska="'#-#-#'" />
</template>

<script>
import { ref, defineComponent } from "vue";
import { maska } from "maska";
export default defineComponent({
  setup() {
    const value = ref("");

    return { value };
  },
  directives: { maska },
  watch: {
    value(n) {
      this.$emit("input", n);
    },
  },
});
</script>

Try this way:

  • in your main.js instead app.directive("v-mask", maska) go with app.use(maska)
  • in phone.vue instead v-mask="'#-#-#'" go with v-maska="'#-#-#'"

codesandbox

发布评论

评论列表(0)

  1. 暂无评论