<div id="test">
<select v-model="selected">
<option v-for="yx in YX" :value="yx.text">
{{yx.text}}
</option>
</select>
<select>
<option v-for="zy in selection" :value="zy.text" :selected="$index == 0 ? true : false">
{{zy.text}}
</option>
</select>
</div>
new Vue({
el: '#test',
data: {
selected: '计信院', //AJAX接入数据时候,这里需要手动设置,否则报错
YX: [{
text: '计信院',
ZY: [{
text: '软件工程'
}, {
text: '计算机科学与技术'
}, {
text: "信息安全"
}, ]
}, {
text: '商学院',
ZY: [{
text: '旅游管理'
}, {
text: '工商管理'
}, {
text: "行政管理"
}, ]
}, ]
},
computed: {
selection: {
get: function() {
var that = this;
return this.YX.filter(function(item) {
return item.text == that.selected;
})[0].ZY;
}
}
}
});
来源:https://segmentfault.com/q/1010000004003248/a-1020000004006124
