


Use angular, react and vue to implement the same interview question component
React, angular, and vue are all three frameworks that have become popular recently. This article mainly introduces to you the relevant content about angular, react, and vue implementing the same interview question components. I will share them for your reference and study. I will not say anything else below. Enough said, let’s take a look at the detailed introduction.
Interview question requirements are as follows
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script src="angular-1.4.6.js"></script> <style> .del{ text-decoration: line-through; color: red; } .in1{ margin-left: 40px; } </style> </head> <body ng-app="app" ng-controller="my-ctrl"> <input type="text" ng-model="val"> <button ng-click="add()">添加</button> <ul> <li ng-repeat="(key,item) in items" ng-show="flag||!items[key].labs" ng-class={true:'del',false:'unselected'}[items[key].labs]><input type="checkbox" ng-click="labe()" ng-model="lab">{{item.text}}<input type="button" value="删除" ng-click="delate()" class="in1"></li> </ul> <button type="button" ng-click="showall()">已完成开关显示</button> <button type="button" ng-click="delateall()">清除已完成</button> </body> <script type="text/javascript"> var myapp = angular.module("app",[]); myapp.controller("my-ctrl",function($scope){ $scope.items = []; $scope.flag = 1; $scope.add=function(){ $scope.items.unshift({text:$scope.val,labs:0}); } $scope.delate=function(){ $scope.items.splice(this.$index,1); } $scope.labe=function(){ $scope.items[this.$index].labs=this.lab; } $scope.showall=function(){ if($scope.flag == 0){ $scope.flag = 1; } else{ $scope.flag = 0; } } //倒序删除数组元素 //这里必须使用倒叙删除数组因为angular数据双向绑定,正序的话会导致数据随时更新影响for循环 $scope.delateall=function(){ for(var i=$scope.items.length-1;i>=0;i--){ if($scope.items[i].labs==true){ $scope.items.splice(i,1); } } } //delateall除了这种方式书写还有另外一种正序删除的方式 //$scope.delateall=function(){ //$scope.delall=[]; //for(var i=0;i<$scope.items.length;i++){ //if($scope.items[i].labs == true){ //console.log(i); //$scope.delall.push(i); //} //} //console.dir($scope.delall); //for(var j=0;j<$scope.delall.length;j++){ //if(j==0){ //$scope.items.splice($scope.delall[j],1); //} //else{ //$scope.items.splice(($scope.delall[j]-j),1); //} //} //console.dir($scope.items); //} }) </script> </html>
import React, { Component } from 'react'; import './App.css'; class App extends Component { constructor(){ super(); this.state={ alll:[], values:'', flag:true } } add(e){ let arr1 = this.state.alll; arr1.push({msg:this.state.values,check1:false}); this.setState({ alll:arr1 }) console.log(this.state.alll); } change(e){ this.setState({ values:e.nativeEvent.target.value }) } delate(e){ let index1 = e.target.parentNode.id; let arr1 = []; for(var i =0;i<this.state.alll.length;i++){ arr1.push(JSON.parse(JSON.stringify(this.state.alll[i]))); } arr1.splice(index1,1); console.log(arr1); this.setState( {alll: arr1}, () =>{ alert(1); console.log(this.state.alll) } ) } checktoggle(e){ let index1 = e.target.parentNode.id; let arr1 = this.state.alll; arr1[index1].check1 = !arr1[index1].check1; this.setState({ alll:arr1 }) console.log(this.state.alll); } hideandshow(e){ this.setState({ flag : !this.state.flag }) } removeAll(){ let arr1 = []; for(var i =0;i<this.state.alll.length;i++){ arr1.push(JSON.parse(JSON.stringify(this.state.alll[i]))); } for(let i = arr1.length-1;i>-1;i--){ console.log(i); if(arr1[i].check1 === true){ arr1.splice(i,1); } } this.setState({ alll:arr1 }) console.log(this.state.alll); } render() { var result = []; for(let i = 0;i<this.state.alll.length;i++){ result.push(<p key={i} id={i} className={this.state.flag||!this.state.alll[i].check1?'dis1':'disn'}><input type="checkbox" onClick={this.checktoggle.bind(this)} checked={this.state.alll[i].check1} name={i} /><span className={this.state.alll[i].check1?'del1':''}>{this.state.alll[i].msg}</span><input type="button" value="删除" onClick={this.delate.bind(this)} className="in" /></p>) } return ( <p className="App"> {this.state.values} <input type="text" placeholder="请添加事件" className="in" onChange={this.change.bind(this)} /> <input type="button" value="添加" onClick={this.add.bind(this)}/> <ul ref="ul1"> {result} </ul> <input type="button" value="已完成显示开关" className="in" onClick={this.hideandshow.bind(this)}/> <input type="button" value="清除已完成" className="in" onClick={this.removeAll.bind(this)}/> </p> ); } } export default App; //使用react写时,数组的复制有使用的不标准,正确的深度复制应该转化为字符串以后再复制,类似于代码中removeAll复制的方式。但是在当前实例中浅复制也可以完成功能。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script src="vue2.0.js"></script> <style> .in{ margin:20px; } .cl1{ text-decoration: line-through; color: red; } .cl2{ } </style> </head> <body> <p id="app"> <input type="text" placeholder="请添加事件" class="in" v-model="msg"/> <input type="button" value="添加" @click="add()"/> <p v-for="(item,index) in alll" :key="index" :id="index" v-if="flag1||!item.check1"> <input type="checkbox" class="in" @click="clickChecked" :checked="item.check1"/> <span>{{item.msg1}}</span> <input type="button" value="删除" class="in" @click="delate"/> </p> <p> <input type="button" value="已完成显示开关" class="in" @click="showAll"/> <input type="button" value="清除已完成" class="in" @click="removeAll($event)"/> </p> </p> <script> new Vue({ el:'#app', data:{ msg:'', alll:[], flag1:true, }, methods:{ add(){ this.alll.unshift({msg1:this.msg,check1:false}); console.log(this.alll) }, delate(e){ let index1 = e.target.parentNode.id; this.alll.splice(index1,1); console.log(this.alll); }, clickChecked(e){ let index1 = e.target.parentNode.id; this.alll[index1].check1 = !this.alll[index1].check1; }, showAll(){ this.flag1 = !this.flag1; }, removeAll(){ console.log(this.alll); for(var i =this.alll.length-1;i>-1;i--){ if(this.alll[i].check1==true){ this.alll.splice(i,1); } } // for(let i = 0;i<this.alll.length;i++){ // if(this.alll[i].check1==true){ // this.alll.splice(i,1); // } // }//由于vue的数据双向绑定,从前到后遍历删除存在错误。 } } }) </script> </body> </html>
The above is the detailed content of Use angular, react and vue to implement the same interview question component. 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

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

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

React front-end and back-end separation guide: How to achieve front-end and back-end decoupling and independent deployment, specific code examples are required In today's web development environment, front-end and back-end separation has become a trend. By separating front-end and back-end code, development work can be made more flexible, efficient, and facilitate team collaboration. This article will introduce how to use React to achieve front-end and back-end separation, thereby achieving the goals of decoupling and independent deployment. First, we need to understand what front-end and back-end separation is. In the traditional web development model, the front-end and back-end are coupled

How to use React and Flask to build simple and easy-to-use web applications Introduction: With the development of the Internet, the needs of web applications are becoming more and more diverse and complex. In order to meet user requirements for ease of use and performance, it is becoming increasingly important to use modern technology stacks to build network applications. React and Flask are two very popular frameworks for front-end and back-end development, and they work well together to build simple and easy-to-use web applications. This article will detail how to leverage React and Flask

How to build a reliable messaging application with React and RabbitMQ Introduction: Modern applications need to support reliable messaging to achieve features such as real-time updates and data synchronization. React is a popular JavaScript library for building user interfaces, while RabbitMQ is a reliable messaging middleware. This article will introduce how to combine React and RabbitMQ to build a reliable messaging application, and provide specific code examples. RabbitMQ overview:

Angular.js is a freely accessible JavaScript platform for creating dynamic applications. It allows you to express various aspects of your application quickly and clearly by extending the syntax of HTML as a template language. Angular.js provides a range of tools to help you write, update and test your code. Additionally, it provides many features such as routing and form management. This guide will discuss how to install Angular on Ubuntu24. First, you need to install Node.js. Node.js is a JavaScript running environment based on the ChromeV8 engine that allows you to run JavaScript code on the server side. To be in Ub

ReactRouter User Guide: How to Implement Front-End Routing Control With the popularity of single-page applications, front-end routing has become an important part that cannot be ignored. As the most popular routing library in the React ecosystem, ReactRouter provides rich functions and easy-to-use APIs, making the implementation of front-end routing very simple and flexible. This article will introduce how to use ReactRouter and provide some specific code examples. To install ReactRouter first, we need

How to use React and Apache Kafka to build real-time data processing applications Introduction: With the rise of big data and real-time data processing, building real-time data processing applications has become the pursuit of many developers. The combination of React, a popular front-end framework, and Apache Kafka, a high-performance distributed messaging system, can help us build real-time data processing applications. This article will introduce how to use React and Apache Kafka to build real-time data processing applications, and

PHP, Vue and React: How to choose the most suitable front-end framework? With the continuous development of Internet technology, front-end frameworks play a vital role in Web development. PHP, Vue and React are three representative front-end frameworks, each with its own unique characteristics and advantages. When choosing which front-end framework to use, developers need to make an informed decision based on project needs, team skills, and personal preferences. This article will compare the characteristics and uses of the three front-end frameworks PHP, Vue and React.

The default display behavior for components in the Angular framework is not for block-level elements. This design choice promotes encapsulation of component styles and encourages developers to consciously define how each component is displayed. By explicitly setting the CSS property display, the display of Angular components can be fully controlled to achieve the desired layout and responsiveness.
