• Asp.net MVC 使用 ReactJS


    新建项目

    1. 新建MVC4 项目
    2. 安装ReactJS.NET
    3. 新建ReactJSController
      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
      using System.Web.Mvc;
      
      namespace ReactJsDemo.Controllers
      {
          public class ReactJSController : Controller
          {
              //
              // GET: /ReactJS/
              public ActionResult Index()
              {
                  return View();
              }
      	}
      }
      
      1. 新建视图 Index.cshtml
        @{
            ViewBag.Title = "Index";
        }
        @section styles{
            <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
            <style type="text/css">
                body {
                    padding-top: 50px;
                    padding-bottom: 20px;
                }
            </style>
        }
        @section scripts{
            <script src="http://cdn.bootcss.com/jquery/2.1.4/jquery.min.js"></script>
            <script src="http://cdn.bootcss.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> 
            <script src="http://cdn.bootcss.com/react/0.14.4/react.min.js"></script>
            <script src="http://cdn.bootcss.com/react/0.14.4/react-dom.min.js"></script>
        
            <script src="~/Scripts/HelloWorld.jsx" ></script>
        }
        
        <div id="content"></div>
        

          

          
    4. 新建 React jsx 文件 HelloWorld.jsx
      var Hello = React.createClass({
              getInitialState: function () {
                return {
                  opacity: 1.0
                };
              },
      
              componentDidMount: function () {
                this.timer = setInterval(function () {
                  var opacity = this.state.opacity;
                  opacity -= .05;
                  if (opacity < 0.1) {
                    opacity = 1.0;
                  }
                  this.setState({
                    opacity: opacity
                  });
                }.bind(this), 100);
              },
      
              render: function () {
                return (
                  <div style={{opacity: this.state.opacity}}>
                    Hello {this.props.name}
                  </div>
                );
              }
            });
      ReactDOM.render(
        <Hello  name="world" />,
        document.getElementById('content')
      );

       OK 运行项目

  • 相关阅读:
    模板之st表
    codevs 1163 访问艺术馆
    noip提高组2000 乘积最大
    [HNOI2008]越狱(luogu P3197)
    [ZJOI2009]假期的宿舍(luogu P2055)
    noip普及组2013 车站分级(luogu P1983)
    [HNOI2010]平面图判定
    sql中对于case when...then...else...end的写法和理解
    java中,去除空白的方法
    关于debug时的一些操作
  • 原文地址:https://www.cnblogs.com/AskySun/p/5114048.html
Copyright © 2020-2023  润新知