[Solved] [V1] QInput v-slot: is that possible to get the attribute of QInput
-
<template> <div class="fixed-center text-center"> <q-input v-model="text1" label="Label" readonly> <template v-slot:after> <q-icon name="search" @click="(evt, ??) => test(evt, ??)" class="cursor-pointer"/> </template> </q-input> <q-input v-model="text2" label="Label"> <template v-slot:after> <q-icon name="search" @click="(evt, ??) => test(evt, ??)" class="cursor-pointer"/> </template> </q-input> </div> </template> <script> export default { data () { return { text1: '', text2: '' } }, methods: { test (evt, ??) { // how to get current QInput attribute, for example, readonly } } } </script>
Thanks a lot for your help!
-
@Stanley assign a
ref
on your q-input. then you can dothis.$refs.yourRef.$props
/$attrs
. -
@metalsadman Thanks!
This can be a workaround. But if there are 100 QInput or even more, does that mean I have to set ref one by one?For a more complex scenario, if I embed QInput into QTable, it is also difficult to name the ref.
-
@Stanley you can name refs with let’s say the index of your table columns, otherwise you should rethink what you want to achieve there. or you could make use of the props exposed by qtable and check your value from your row data / column definitions.
-
@metalsadman
Yes, I agree with you.
Last question, will it cause performance issue if there are too much refs? -
@Stanley not so much i think. $refs is a vue object. so you can do
$refs['yourUniqueRefname']
. -
@metalsadman thank you very much!