当前位置:   article > 正文

浅谈web前端常用的三大主流框架_前端三大框架会几个

前端三大框架会几个

讲到前端的框架,大家想必都能脱口而出:Angular、React、Vue,那么这几个框架的优缺点,以及在项目当中如何抉择框架的使用等等,本篇就将介绍这三大框架的使用感受

双向绑定

开篇就用这三大框架的双向绑定的实现作为一个 demo 引入,通过这三大框架的双向绑定能够简单的了解三大框架在编码上的一些区别以及其的简易程度,从下面的代码简洁程度来讲,vue.js 给我们带来的体验还是不错的

Angular

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>

</head>

<body ng-app="MyModule">
  <div ng-controller="MyCtrl">
     <input type="text" ng-model="message">
    <h1>{{ message }}</h1>
  </div>

  <script src="https://cdn.bootcss.com/angular.js/1.7.8/angular.min.js"></script>
  <script>
    // 这边使用到的是推断型依赖注入
    const MyModule = angular.module("MyModule", [])

    const MyCtrl = function ($scope) {
      $scope.message = 'Hello world !!!'
    }

    MyModule.controller('MyCtrl', MyCtrl)
  </script>
</body>

</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

React

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <div id="root"></div>

  <script src="https://cdn.bootcss.com/react/16.9.0-alpha.0/umd/react.development.js"></script>
  <script src="https://cdn.bootcss.com/react-dom/16.8.6/umd/react-dom.development.js"></script>
  <!-- 注意这边的 babel 只能用 5.x 以下版本的 -->
  <script src="https://cdn.bootcss.com/babel-core/5.8.38/browser.min.js"></script>
  <script type="text/babel">
    // 这边使用到的是 JSX 语法,React 内部并没有实现双向绑定,所以这边使用了 input 的 change  事件来实现双向绑定
    class Input extends React.Component {
      constructor(props) {
        super(props)
        this.state = {
          message: 'Hello world !!!'
        }
        this.handleChange = this.handleChange.bind(this)
      }
      handleChange(event) {
        this.setState({
          message: event.target.value
        });

      }
      render() {
        var message = this.state.message;
        return ( 
          <div>
            <input type = "text" value = { message } onChange = { this.handleChange } /> 
            <h1> { message } </h1> 
          </div>
        );
      }
    }

    ReactDOM.render(<Input/>, document.getElementById('root'));
  </script>
</body>

</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49

Vue

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>

</head>

<body>
  <div id="app">
    <input type="text" v-model="message">
    <h1>{{ message }}</h1>
  </div>

  <script src="https://cdn.bootcss.com/vue/2.6.10/vue.min.js"></script>
  <script>
    new Vue({
      el: '#app',
      data() {
        return {
          message: 'Hello world !!!'
        }
      }
    })
  </script>
</body>

</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

最后,给大家推荐一个前端学习进阶内推交流群685910553前端资料分享),不管你在地球哪个方位,
不管你参加工作几年都欢迎你的入驻!(群内会定期免费提供一些群主收藏的免费学习书籍资料以及整理好的面试题和答案文档!)

如果您对这个文章有任何异议,那么请在文章评论处写上你的评论。

如果您觉得这个文章有意思,那么请分享并转发,或者也可以关注一下表示您对我们文章的认可与鼓励。

愿大家都能在编程这条路,越走越远。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/375970
推荐阅读
相关标签
  

闽ICP备14008679号