The implementation method of adding prompts in uniapp: first judge the input and obtain the focus; then obtain the data through the interface and perform front-end simulation processing; then set the change event of the input box; finally set the click event and implement the search click Can.
The operating environment of this tutorial: Windows 7 system, uni-app2.5.1 version. This method is suitable for all brands of computers.
Recommended (free): uni-app development tutorial
uniapp implements a search and prompt function (including passing parameters, etc.)
Look at the code first, copy it and use it. I have helped you consider using v-for loops or other possible problems. question. (It is recommended that you install the plug-in and use scss) You will see the following effect.
<template> <view> <input> <!-- 判断input获取焦点同时后台给到了数据 --> <view> <view> {{item.title}} </view> </view> </view></template><script> export default { data() { return { Value: '', //搜索内容 placeholder: '请输入搜索内容', //提示 isValue: false, //文字框是否显示 SearchList: [] } }, methods: { ShowValue() { this.isValue = !this.isValue if (this.isValue) { //如果获取到了焦点 this.getList() } else { //失去焦点 清空数据 } }, getList(value) { //这一步是获取数据 您可以通过接口获取 这里做前端模拟处理 // 需要和后台协商没有数据时候传递默认的几条 // axios.get('/getList?value='+value).then(res=>{ //请求案例 // this.SearchList = res.data.data // }) if (!value) { let arr = [{ id: 1, title: "我是搜索信息1" }, { id: 2, title: "我是搜索信息2" }, { id: 3, title: "我是搜索信息3" }, { id: 4, title: "我是搜索信息4" }, { id: 5, title: "我是搜索信息5" }, ] this.SearchList = arr } else { this.getList() } }, GetValue(event) { //input框的change事件 console.log('当前输入' + event.detail.value) // 有值就获取 没有就让他为空 event.detail.value ? this.Value = event.detail.value : this.Value = '' event.detail.value ? this.getList(this.Value) : this.getList(this.Value) }, SetValue(value) { //点击事件 搜索点击这一条 console.log('搜索信息为' + value) this.Value = value this.placeholder = value this.SearchList = [] this.isValue = !this.isValue // 拿到数据 做页面跳转操作比如 // uni.navigateTo({ // url:"../cart/cart" // }) } }, onLoad() {} }</script><style> $max:100%; .box { width: $max; padding: 10 30rpx; //上下10 左右30 height: 64rpx; display: flex; justify-content: center; align-items: center; min-height: 32px; position: relative; background: #409EFF; .S-input { width: 660rpx; background: #f7f7f7; padding-left: 30rpx; border-radius:32rpx; } .InputList { position: absolute; width: 690rpx; height: auto; min-height: 100rpx; top: 74rpx; border: 1rpx solid #409EFF; border-radius: 5rpx; padding: 10rpx; .listSon { height: 50rpx; line-height: 50rpx; font-size: 32rpx; text-indent:1em; } .listSon:nth-of-type(even){ background: #f7f7f7; } } }</style>
Additional and possible useful information has been commented
If you have any other questions about uniapp or if you don’t understand this method, you can leave a message , I will reply as soon as possible and help you solve it.
The above is the detailed content of How does uniapp implement the function of adding prompts. For more information, please follow other related articles on the PHP Chinese website!

The article discusses debugging strategies for mobile and web platforms, highlighting tools like Android Studio, Xcode, and Chrome DevTools, and techniques for consistent results across OS and performance optimization.

The article discusses debugging tools and best practices for UniApp development, focusing on tools like HBuilderX, WeChat Developer Tools, and Chrome DevTools.

The article discusses end-to-end testing for UniApp applications across multiple platforms. It covers defining test scenarios, choosing tools like Appium and Cypress, setting up environments, writing and running tests, analyzing results, and integrat

The article discusses various testing types for UniApp applications, including unit, integration, functional, UI/UX, performance, cross-platform, and security testing. It also covers ensuring cross-platform compatibility and recommends tools like Jes

The article discusses common performance anti-patterns in UniApp development, such as excessive global data use and inefficient data binding, and offers strategies to identify and mitigate these issues for better app performance.

The article discusses using profiling tools to identify and resolve performance bottlenecks in UniApp, focusing on setup, data analysis, and optimization.

The article discusses strategies for optimizing network requests in UniApp, focusing on reducing latency, implementing caching, and using monitoring tools to enhance application performance.

The article discusses optimizing images in UniApp for better web performance through compression, responsive design, lazy loading, caching, and using WebP format.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

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

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver Mac version
Visual web development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.
