


Introduction to the solution to the problem of implementing IP input box on vue mobile terminal
This article brings you an introduction to the method of dynamically defining functions in Python. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
The vue framework uses the IP input box component on the mobile side, and the input is compatible with the browser and WeChat.
Requirements: Only numbers can be entered. When characters other than numbers are entered (including dots, colons and other numeric symbols), it will automatically jump to the next IP input box.
type=number type, the input of dots will not be prohibited. Manual filtering cannot get strings containing dot characters. Moreover, after entering multiple dots, the value obtained is empty.
Solution: type=tel, only numbers can be entered, and input of dot characters can be obtained
Problem: The keyup event under WeChat is invalid. The event.keyCode returned in the callback event is all 229.
Solution: Listen to the input event. The keycode in the event event object is empty, but event.data returns the input characters, which can be filtered. .
<template> <div> <ul> <li> <input> <span>.</span> </li> </ul> </div> </template> <script> export default { data() { return { ipAdress: [{ value: '' }, { value: '' }, { value: '' }, { value: '' }], isWX:navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == "micromessenger" }; }, props: { ipStr: { trype: String, default: '' }, ipType: { type: String }, isDisabled: { type: Boolean, default: false }, width: { type: String, default:'100%' } }, watch: { ipStr:{ immediate:true, handler:function(vall) { let val = vall; let nArr = []; if(val && val.includes('.') && val.length > 0) { let valArr = val.split('.'); let m = valArr.length; for(let i = 0; i < 4; i++) { if(valArr[i] == 'null' || valArr[i] == 'undefined'){ valArr[i] = ''; } if(i < m) { nArr.push({ value: valArr[i] }); } else { nArr.push({ value: '' }); } } } else { nArr = [{ value: '' }, { value: '' }, { value: '' }, { value: '' }]; } this.ipAdress = nArr; } } }, methods: { //methods blurFocus(index) { if(index == 3) { this.$emit('blur'); } }, checkIpVal(item,index,event) { let self = this; //wx if(this.isWX){ let e = event || window.event; let keyCode = e.data; // //.向右跳转 if(keyCode === ".") { e.preventDefault(); e.returnValue = false; item.value = item.value.replace(/[^\d]/g, "").replace(/[\.]/g, ""); if(index < 3 ) { self.$refs.ipInput[index + 1].focus(); } return false; } } let isNo = /^[0-9]{1,3}$/g; if(/[^\d]/g.test(item.value)){ let cache = JSON.parse(JSON.stringify(self.ipAdress)); cache[index].value = item.value.replace(/[^\d]/g, "").replace(/[\.]/g, ""); self.ipAdress = cache; return false; } if(item.value.replace(/[^\d]/g, "").length >= 3) { let val = parseInt(item.value.replace(/[^\d]/g, ""), 10); if(isNaN(val)) { val = '' } else if(val > 255) { val = 255; } else { val = val < 0 ? 0 : val; } item.value = String(val); this.$set(this.ipAdress,index,item); if(index < 3 ) { self.$refs.ipInput[index + 1].focus(); } } let ns = ''; this.ipAdress.forEach(item => ns += '.' + item.value); if(ns.length <= 4){ this.$emit('getIP', "", this.ipType); }else{ this.$emit('getIP', ns.slice(1), this.ipType); } }, turnIpPOS(item, index, event) { let self = this; let e = event || window.event; if(e.keyCode == 37) { if(index != 0) { self.$refs.ipInput[index - 1].focus(); } } //右箭头、回车键、空格键、冒号均向右跳转,右一不做任何措施 if(e.keyCode == 39 || e.keyCode == 13 || e.keyCode == 32 || e.keyCode == 110 || e.keyCode == 46 || e.keyCode == 190 ) { e.preventDefault(); e.returnValue = false; if(index < 3 ) { self.$refs.ipInput[index + 1].focus(); } return false; } }, delteIP(item, index, event) { let self = this; let e = event || window.event; let val = parseInt(item.value.replace(/[^\d]/g, ""), 10); val = isNaN(val) ? '' : val; if(e.keyCode == 8 && index > 0 && val.length==0) { self.$refs.ipInput[index - 1].focus(); } } }, mounted(){ console.log(this.$props) console.log(this.$attrs.index) } }; </script> <style> $--border-color:#ccc; $--outline-color:transparent; $--font-color:$--input-color; $base-font-size:12px; .ipInput { box-sizing: border-box; line-height: inherit; border: 1px solid $--border-color; overflow: hidden; border-radius: 5px; padding: 0; margin: 0; display: inline-block; vertical-align: middle; outline: $--outline-color; font-size:0; text-indent: 0; background: #fff; &.isDisabled { background: $--outline-color; li{ cursor:not-allowed; input{ cursor:not-allowed; } } } li { display: inline-block; width:25%; box-sizing: border-box; font-size:0; input { appearance: none; padding:10px 5px; width: calc(100% - 3px); text-align: center; outline: none; border: none; color: $--font-color; box-sizing: border-box; font-size: $base-font-size; &:disabled { background: $--outline-color; } } span { display: inline-block; font-size:$base-font-size; width: 3px; color: $--font-color; } } } </style>
This article has ended here. For more exciting content, you can pay attention to the JavaScript Tutorial Video column of the PHP Chinese website!
The above is the detailed content of Introduction to the solution to the problem of implementing IP input box on vue mobile terminal. For more information, please follow other related articles on the PHP Chinese website!

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.


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

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft