4

Given the following code below where <v-input> is a custom input element,

<template>
    <v-input id="username" type="text" v-model="username" />
</template>

<script>
export default {
    data() {
        return {
            username: "",
        };
    },
};
</script>

How would one go about modifying the value of the input element through the browser console? I have tried the following code below but it does not bind to the Vue component.

const element = document.querySelector("#username");
element.value = "foobar"

I've also tried emitting custom events but those don't seem to work for me either. Any advice regarding this would be much appreciated.

1 Answer 1

3

I figured it out, I need only dispatch a new input event so that Vue.js catches the value. See below for an example.

const inputBox = document.querySelector("#inputBox");

inputBox.value = "hello";
inputBox.dispatchEvent(new Event('input'));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.