I’m developing a UXP project using Vue 3. I’m facing an issue where I can’t obtain the input content in the sp - textfield
component.
I’ve attempted different binding methods such as v-model
and :value
, but I’m still unable to get the value entered in the text field. Here are the code snippets I’ve used:
Binding with v-model
<template>
<div class="search">
<sp-textfield ref="textfield" v-model="modelValue" id="inputField" class="searchTextField" type="text" size="s" placeholder=""/>
<sp-button @click="searchBtn" variant="primary" size="s">Search</sp-button>
</div>
</template>
<script setup>
import { ref } from 'vue';
const modelValue = ref(null);
const searchBtn = () => {
console.log('modelValue', modelValue.value);
};
</script>
Binding with :value
<template>
<div class="search">
<sp-textfield ref="textfield" :value="modelValue" id="inputField" class="searchTextField" type="text" size="s" placeholder=""/>
<sp-button @click="searchBtn" variant="primary" size="s">Search</sp-button>
</div>
</template>
<script setup>
import { ref } from 'vue';
const modelValue = ref(null);
const searchBtn = () => {
console.log('modelValue', modelValue.value);
};
</script>
In both cases, when I click the “Search” button, the console always prints an empty value for modelValue
.
I also tried using the official example code to get the input value:
document.querySelector(".yourTextField").addEventListener("input", evt => {
console.log(`New value: ${evt.target.value}`);
})
But this also didn’t work.