Outside of the template, I access the parameter name, for example:
let option_name = this.options[event.target.options.selectedIndex].name
To do this, use this approach to customize your template:
Your parameters are defined in an array like [{"name":"Bar","value":1},{"name":"Baz","value":2}]
... etc.
Put your parameters in the data
function of the <script>export default {function data(){return { options }}}</script>
Load options
into the template using v:for
: <option v-for="option in options" v-bind:value="option.value">{{option.name}}</option>
Use @change="getOptionName"
in the select
element:
<select @change="getOptionName">
In your methods
get the name:
getOptionName(event){ let option_name = this.options[event.target.options.selectedIndex].name }
Please note that in this case, the object
options
in event.target.options
has nothing to do with your data named options
... hope this avoids confusion
So, a more advanced approach, but I think that when everything is set up correctly, getting a name is not scary, although it may be easier.
source share