If I have the following HTML code:
<select class="form-control" name="gateway">
<option data-type="typeA" value="1">Test String</option>
<option data-type="typeB" value="2">Test String</option>
<option data-type="typeC" value="3">Test String</option>
</select>
<span>@{{ typeMapper(data-type) }}</span>
And this Vue.js script:
const app = new Vue({
el: '#vue-app',
data: {},
methods: {
typeMapper: function (type) {
var array = {
'typeA':'You selected Type A',
'typeB':'You selected Type B',
'typeC':'You selected Type C',
};
return array[type];
}
}
});
How can we retrieve the data-type
values in Vue.js?
The goal is to pass the selected option's data-type
value to the Vue.js typeMapper method and display the result in the span
tag.
We are unsure of how to achieve passing the data-type
value to Vue.js!
For reference, we are using Vue.js 2.