<body>
<div id="app">
<h2>自定义下拉框</h2>
<table>
<!-- <tr is="custom-select" btn-value="chaxun"></tr> -->
<custom-select btn-value="查询" v-bind:list="list1"></custom-select>
</table>
<h2>自定义下拉框</h2>
<custom-select btn-value="go" v-bind:list="list2"></custom-select>
</div>
<script>
var obj = {
selectShow: false
}
Vue.component("custom-select",{
data:function(){
return {
selectShow:false,
val:''
};
},
props:['btnValue','list'],
template: `
<section class="wrap">
<div class="searchInput clearfix">
<div class="clearfix">
<input type="text" class="keyword" @click="selectShow=!selectShow" v-model="val">
<input type="button" class="go" value="go" v-bind:value = "btnValue" >
<span></span>
</div>
<custom-list v-show="selectShow" :list="list" @receive="changeValue"></custom-list>
</div>
</section>
`,
methods:{
changeValue(value){
this.val = value;
}
}
})
Vue.component("custom-list",{
props:["list"],
template:`
<ul class="list" >
<li v-for="item of list" @click="selectValue(item)">{{item}}</li>
</ul>
`,
methods:{
selectValue:function(item) {
this.$emit("receive",item)
}
}
})
new Vue({
el:"#app",
data:{
list1:["beijing","chengdu","wuhan","shanghai"],
list2:["mon","tues","wed","thurs"]
}
})
</script>
<div id="app">
<h2>自定义下拉框</h2>
<table>
<!-- <tr is="custom-select" btn-value="chaxun"></tr> -->
<custom-select btn-value="查询" v-bind:list="list1"></custom-select>
</table>
<h2>自定义下拉框</h2>
<custom-select btn-value="go" v-bind:list="list2"></custom-select>
</div>
<script>
var obj = {
selectShow: false
}
Vue.component("custom-select",{
data:function(){
return {
selectShow:false,
val:''
};
},
props:['btnValue','list'],
template: `
<section class="wrap">
<div class="searchInput clearfix">
<div class="clearfix">
<input type="text" class="keyword" @click="selectShow=!selectShow" v-model="val">
<input type="button" class="go" value="go" v-bind:value = "btnValue" >
<span></span>
</div>
<custom-list v-show="selectShow" :list="list" @receive="changeValue"></custom-list>
</div>
</section>
`,
methods:{
changeValue(value){
this.val = value;
}
}
})
Vue.component("custom-list",{
props:["list"],
template:`
<ul class="list" >
<li v-for="item of list" @click="selectValue(item)">{{item}}</li>
</ul>
`,
methods:{
selectValue:function(item) {
this.$emit("receive",item)
}
}
})
new Vue({
el:"#app",
data:{
list1:["beijing","chengdu","wuhan","shanghai"],
list2:["mon","tues","wed","thurs"]
}
})
</script>