抄了一段vue的实例,为什么v-for属性不能用
发布网友
发布时间:2022-04-20 19:17
我来回答
共1个回答
热心网友
时间:2023-10-09 06:57
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1,IE=edge">
<title>title</title>
<link href="" rel="stylesheet">
<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div id="app">
<vselect :value="value" :options="options">
</vselect>
</div>
</body>
<script type="text/javascript">
Vue.component('vselect', {
//键值不为空才加入到option中
template: "<span><select v-model='selected'>"+
"<option v-for='option in options'"+
" v-if='$key'>{{ option }}</option></select></span>",
props: { selected: String,
options: Object,
value:Number
}
});
new Vue({
el: '#app',
data:{
//加一对空的键值
options:{'':'test','1':'Lars','2':'Admin','3':'ewrewrew'}
}
});
</script>
</html>