Detailed explanation of vue Element-ui input remote search example
This article is divided into html, js and css codes to give you a detailed introduction to vue Element-ui input remote search and modification suggestion display template functions. Friends who are interested should take a look at it. I hope it can help everyone.
html:
<template> <el-autocomplete popper-class="my-autocomplete" custom-item="my-remote" v-model="state" :fetch-suggestions="querySearch" placeholder="默认空" icon="close" :on-icon-click="handleIconClick"> </el-autocomplete> </template>
js:
<script> import Vue from 'vue' Vue.component('my-remote', { functional: true, render: function(h, ctx) { var item = ctx.props.item; let str = h('li', ctx.data, [ h('p', { attrs: { class: 'name' } }, [item.value]), h('span', { attrs: { class: 'addr' } }, [item.address]) ]); if (item.str) { // 根据参数不同 修改原模版结构 str = h('center', { attrs: { class: 'ems' } }, [item.str]) } return str }, props: { item: { type: Object, required: true } } }); export default { data() { return { restaurants: [], state: '', timeout: null, _that: {} // 记录this,用来发起http请求 }; }, methods: { querySearch(queryString, cb) { let restaurants = this.restaurants; if (restaurants.length > 0) { // 如果参数都没变化,则使用缓存数据,避免请求沉积 let results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants; cb(results); } else { const qtype = ‘参数'; this._that.$http('/inner', { qtype: qtype }) .then((res) => { restaurants = this.loadAll(res); this.restaurants = restaurants; let results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants; cb(results); }) .catch((err) => { restaurants = this.loadAll(); let results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants; cb(results); }); } }, createFilter(queryString) { return (restaurant) => { if (restaurant.str) return false; return (restaurant.value.indexOf(queryString.toLowerCase()) === 0); }; }, loadAll(data) { let serier = []; if (data) { for (let i = 0, l = data.length; i < l; i++) { let a = data[i]; let b = ''; if (typeof a === "object") { b = a[1]; a = a[0]; } serier.push({ "value": a, "address": b }) } } else { // 如果没有请求到数据,则显示暂无数据! serier.push({ "str": '暂无数据' }) } return serier; }, handleIconClick(ev) { this.state = ""; } }, mounted() { this._that = this; } } </script>
css:
<style lang="scss"> .my-autocomplete { li { line-height: normal !important; padding: 7px !important; .name { text-overflow: ellipsis; overflow: hidden; } .addr { font-size: 12px; color: #b4b4b4; } .highlighted .addr { color: #ddd; } } .ems { font-size: 12px; color: #b4b4b4; } } </style>
Related recommendations:
JavaScript replace implementation search Keyword highlighting method
jquery select plug-in asynchronous real-time search implementation method
Bootrap and Vue implementation of Baidu-like search function example
The above is the detailed content of Detailed explanation of vue Element-ui input remote search example. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Introduction to how to use Vue and Element-UI to implement calendar and date selection functions: In front-end development, calendar and date selection functions are one of the very common requirements. Vue and Element-UI are a pair of very powerful development tools. Combining them can easily implement calendar and date selection functions. This article will introduce how to use Vue and Element-UI to create a simple calendar and date selection function, and provide code examples to help readers understand the specific steps and methods of implementation. Preparation: at the beginning

How to use Vue and Element-UI to implement lazy loading of images Lazy loading (Lazyloading) is a technology that delays loading of images, which can effectively increase page loading speed, save bandwidth and improve user experience. In the Vue project, we can use Element-UI and some plug-ins to implement the image lazy loading function. This article will introduce how to use Vue and Element-UI to implement lazy loading of images, and attach corresponding code examples. 1. Install the necessary dependencies before starting

How to use Vue and Element-UI to implement drag-and-drop sorting function Preface: In web development, drag-and-drop sorting function is a common and practical function. This article will introduce how to use Vue and Element-UI to implement the drag-and-drop sorting function, and demonstrate the implementation process through code examples. 1. Environment setup and installation Node.js Before starting, you need to install Node.js. You can visit https://nodejs.org/ to download and install the version corresponding to the operating system. Install VueCL

How to use Vue and Element-UI to implement message notification functions. With the continuous development of front-end technology, more and more websites and applications need to implement message notification functions in order to display important information to users in a timely manner. In Vue development, this function can be quickly realized by combining the Element-UI framework. This article will introduce in detail how to use Vue and Element-UI to implement the message notification function, and provide relevant code examples. 1. Preparation work is implemented using Vue and Element-UI

How to use Vue and Element-UI to implement data filtering and search functions. In modern web development, data filtering and search functions are very common and important requirements. Vue and Element-UI are currently very popular front-end frameworks. They provide many powerful tools and components that can help us easily implement data filtering and search functions. This article will introduce how to use Vue and Element-UI to implement these functions, and provide detailed code examples. First, we need to prepare a

How to use Vue and Element-UI to implement multi-level drop-down box function Introduction: In web development, multi-level linkage drop-down box is a common interaction method. By selecting an option in a drop-down box, the contents of subsequent drop-down boxes can be dynamically changed. This article will introduce how to use Vue and Element-UI to implement this function, and provide code examples. 1. Preparation First, we need to ensure that Vue and Element-UI have been installed. It can be installed via the following command: npmins

How to create a responsive web interface using Vue and Element-UI In web development, responsive design is an essential technology. Vue.js and Element-UI are two very popular front-end frameworks. They both provide rich tools and components to build modern responsive web interfaces. This article will introduce how to use Vue and Element-UI to create a responsive web interface, and will present the specific implementation process through code examples. First, we need to make sure Vu is installed

How to use Vue and Element-UI to group and summarize data. In front-end development, we often encounter situations where we need to group and summarize data. Vue is a very popular JavaScript framework, and Element-UI is a component library based on Vue. It provides a rich set of UI components that can help us quickly build pages. This article will introduce how to use Vue and Element-UI to group and summarize data, and illustrate it with code examples. Preparatory work
