79285098

Date: 2024-12-16 15:03:36
Score: 1.5
Natty:
Report link

You can handle the @keydown event to detect if the first entered symbol is a space and prevent entering if so. Here is an example:

<script setup>
import { ref } from "vue";

const msg = ref("");

function onInput(e) {
  msg.value = e.target.value;
}

function preventLeadingSpace(e) {
  if (msg.value.length === 0 && e.key === " ") {
    e.preventDefault();
  }
}
</script>

<template>
  <input :value="msg" @input="onInput" @keydown="preventLeadingSpace" />
</template>

Reasons:
  • Has code block (-0.5):
  • User mentioned (1): @keydown
  • Low reputation (1):
Posted by: PerfectM1nd