My problem is that I can not get the value that the <select>
has, although I put the attribute v-model
to the label <select>
and that on the internet I find that it is the correct way, it does not work for me, create this example so that they understand me better and can help me more comfortably.
I'm using Materialize
and doing tests I removed css
to the page to see what happened and curiously to select a <option>
of <select>
if I took the value
, but I have to use Materialize
My goal is to get the value
of the <option>
that has selected the <select>
, I hope you can help me.
I also leave here the fragment of code, what had to happen is that when selecting something, the div
that has the v-if
would appear, if they go to example of codepen and remove the library materialize
css will notice that if it works but when adding the css of materialize
it stops doing it.
$(document).ready(function() {
$('select').material_select();
});
var app = new Vue({
el: "#root",
data: {
elementos: [{
value: '0',
text: 'Seleccionar...'
},
{
value: '1',
text: 'Opcion 1'
},
{
value: '2',
text: 'Opcion 2'
},
],
seleccionado: ""
}
});
body {
background-color: #90a4ae;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>select vue ejemplo pregunta</title>
<link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css'>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div id="root" class="container">
<br><br>
<div class="card-panel blue-grey lighten-5">
<form>
<div class="container-fluid">
<div class="row">
<div class="input-field col s12">
<select v-model="seleccionado">
<option v-for="elemento in elementos" v-bind:value="elemento.value">{{ elemento.text }}</option>
</select>
<label>Materialize Select</label>
</div>
<div class="input-field col s12" v-if="seleccionado != ''">
<label>seleccionado: {{seleccionado}}</label>
</div>
</div>
</div>
</form>
</div>
</div>
<script src='https://code.jquery.com/jquery-3.3.1.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js'></script>
<script src="js/index.js"></script>
</body>
</html>