我希望从这个json数组中填充select选项:
[{"select":["option1","option2","option3","option4"]}]
与vuejs。我找到了一个国家的例子,但不一样(对我来说不管用(。
尝试如下片段:
new Vue({
el: '#demo',
data() {
return {
items: [{"select":["option1","option2","option3","option4"]}],
selected: ''
}
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="demo">
<select v-model="selected">
<option disabled >Please select option</option>
<option v-for="(item, i) in items[0].select" :key="i" :value="item">
{{ item }}
</option>
</select>
<h3>{{ selected }}</h3>
</div>