赞
踩
ElementUI对于初学小白来说可能还有很多不太友好的地方,简单来说就是没有那么通俗易懂,作为一个萌新今天记录一下学习过程中的一些经验。主题为ElementUI的Input自定义模板
示例:
代码如下(示例):
<el-autocomplete popper-class="my-autocomplete" v-model="state" :fetch-suggestions="querySearch" placeholder="请输入内容" @select="handleSelect"> <i class="el-icon-edit el-input__icon" slot="suffix" @click="handleIconClick"> </i> <template slot-scope="{ item }"> <div class="name">{{ item.value }}</div> <span class="addr">{{ item.address }}</span> </template> </el-autocomplete> <style> .my-autocomplete { li { line-height: normal; padding: 7px; .name { text-overflow: ellipsis; overflow: hidden; } .addr { font-size: 12px; color: #b4b4b4; } .highlighted .addr { color: #ddd; } } } </style> <script> export default { data() { return { restaurants: [], state: '' }; }, methods: { querySearch(queryString, cb) { var restaurants = this.restaurants; var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants; // 调用 callback 返回建议列表的数据 cb(results); }, createFilter(queryString) { return (restaurant) => { return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0); }; }, loadAll() { return [ { "value": "三全鲜食(北新泾店)", "address": "长宁区新渔路144号" }, { "value": "Hot honey 首尔炸鸡(仙霞路)", "address": "上海市长宁区淞虹路661号" }, { "value": "新旺角茶餐厅", "address": "上海市普陀区真北路988号创邑金沙谷6号楼113" }, { "value": "泷千家(天山西路店)", "address": "天山西路438号" }, { "value": "胖仙女纸杯蛋糕(上海凌空店)", "address": "上海市长宁区金钟路968号1幢18号楼一层商铺18-101" }, { "value": "贡茶", "address": "上海市长宁区金钟路633号" }, { "value": "豪大大香鸡排超级奶爸", "address": "上海市嘉定区曹安公路曹安路1685号" }, { "value": "茶芝兰(奶茶,手抓饼)", "address": "上海市普陀区同普路1435号" }]; }, handleSelect(item) { console.log(item); }, handleIconClick(ev) { console.log(ev); } }, mounted() { this.restaurants = this.loadAll(); } } </script>
效果截图:![在这里插入图片描述](https://img-blog.csdnimg.cn/10fc58030013461b837e4b179808f41b.png#pic_center)
loadAll(){
request.get("/findAll"//基于axios的请求调用,
).then(res => {
this.restaurants = res.data})
}
mounted() {
this.loadAll();
}
querySearch(queryString, cb) {
var restaurants = this.restaurants;
var results = queryString ? restaurants.filter(this.createFilter(queryString)) : "";
// 调用 callback 返回建议列表的数据
cb(results);
},
createFilter(queryString) {
return (restaurant) => {
return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
};
},
本文简单介绍了一下ElementUI的Input自定义模板的使用,做分享交流之用,水平有限,如有不当,请及时私信联系我!
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。