selected:"A" 对
selected:A 错. 变量不用引号. 内容一定要引号.
selected:A 错. 变量不用引号. 内容一定要引号.
https://jsfiddle.net/rgnuaw30/
h5: 部分
<script src="https://cdn.jsdelivr.net/vue/latest/vue.js"></script>
<div id="app">
<select v-model="selected">
<option v-for="option in options" v-bind:value="option.value">
{{ option.text }}
</option>
</select>
<span>Selected: {{ selected }}</span>
<br>
</div>
<div id="app">
<select v-model="selected">
<option v-for="option in options" v-bind:value="option.value">
{{ option.text }}
</option>
</select>
<span>Selected: {{ selected }}</span>
<br>
</div>
javascript 部分:
var vm=new Vue({
el: '#app',
data: {
selected:"A"
},
computed:{
options:function(){
var array= [
{ text: 'One', value: 'A' },
{ text: 'Two', value: 'B' },
{ text: 'Three', value: 'C' }
];
return array;
},
}
});
el: '#app',
data: {
selected:"A"
},
computed:{
options:function(){
var array= [
{ text: 'One', value: 'A' },
{ text: 'Two', value: 'B' },
{ text: 'Three', value: 'C' }
];
return array;
},
}
});
所有评论(0)