目次
始める前に:
方法
ホームページ バックエンド開発 PHPチュートリアル React コンポーネント プロジェクトの作成に関する実践的な分析

React コンポーネント プロジェクトの作成に関する実践的な分析

Mar 06, 2018 pm 01:24 PM
react 分析する 練習する

React の設計思想は非常にユニークであるため、革新的なイノベーションであり、優れたパフォーマンスを持ち、コードロジックは非常にシンプルです。そのため、注目して利用する人が増えています。この記事では、例を通して React コンポーネント プロジェクトの実践を作成するプロセス全体を紹介します。これに興味のある友人は参照してください。

私が初めて React を書き始めたとき、コンポーネントを書く方法をたくさん見ました。 100 のチュートリアルを作成するには、100 の方法があります。 React 自体は成熟していますが、「正しい」使い方はないようです。そこで、私たちのチームが長年にわたって蓄積してきた React の使用経験をここにまとめます。この記事が初心者でもベテランでも役に立てば幸いです。

始める前に:

表示コンポーネントとコンテナ コンポーネントの違いがよくわからない場合は、まずこの記事を読むことをお勧めします。コメントにメッセージを残してください。 クラスコンポーネントに基づいて

現在、React コンポーネントはクラスベースのコンポーネントを使用して開発されるのが一般的です。次に、同じ行にコンポーネントを記述します:

import React, { Component } from 'react';
import { observer } from 'mobx-react';
import ExpandableForm from './ExpandableForm';
import './styles/ProfileContainer.css';
ログイン後にコピー

I like css in javascript.しかし、このスタイルの書き方はまだ新しすぎます。そこで、各コンポーネントにcssファイルを導入します。また、ローカル導入インポートとグローバルインポートは空白行で区切られます。

状態の初期化


import React, { Component } from 'react'
import { observer } from 'mobx-react'
import ExpandableForm from './ExpandableForm'
import './styles/ProfileContainer.css'
export default class ProfileContainer extends Component {
 state = { expanded: false }
ログイン後にコピー

古いメソッドを使用して、constructorstate を初期化できます。詳細な関連情報はここでご覧いただけます。しかし、私たちはより明確なアプローチを選択します。 constructor里初始化state。更多相关可以看这里。但是我们选择更加清晰的方法。

同时,我们确保在类前面加上了export default。(译者注:虽然这个在使用了redux的时候不一定对)。

propTypes and defaultProps

import React, { Component } from 'react'
import { observer } from 'mobx-react'
import { string, object } from 'prop-types'
import ExpandableForm from './ExpandableForm'
import './styles/ProfileContainer.css'
export default class ProfileContainer extends Component {
 state = { expanded: false }
 static propTypes = {
  model: object.isRequired,
  title: string
 }
 static defaultProps = {
  model: {
   id: 0
  },
  title: 'Your Name'
 }
 // ...
}
ログイン後にコピー

propTypesdefaultProps是静态属性。尽可能在组件类的的前面定义,让其他的开发人员读代码的时候可以立刻注意到。他们可以起到文档的作用。

如果你使用了React 15.3.0或者更高的版本,那么需要另外引入prop-types包,而不是使用React.PropTypes。更多内容移步这里。

你所有的组件都应该有prop types。

方法


import React, { Component } from 'react'
import { observer } from 'mobx-react'
import { string, object } from 'prop-types'
import ExpandableForm from './ExpandableForm'
import './styles/ProfileContainer.css'
export default class ProfileContainer extends Component {
 state = { expanded: false }
 static propTypes = {
  model: object.isRequired,
  title: string
 }
 static defaultProps = {
  model: {
   id: 0
  },
  title: 'Your Name'
 }
 handleSubmit = (e) => {
  e.preventDefault()
  this.props.model.save()
 }
 handleNameChange = (e) => {
  this.props.model.changeName(e.target.value)
 }
 handleExpand = (e) => {
  e.preventDefault()
  this.setState({ expanded: !this.state.expanded })
 }
 // ...
}
ログイン後にコピー


在类组件里,当你把方法传递给子组件的时候,需要确保他们被调用的时候使用的是正确的this。一般都会在传给子组件的时候这么做:this.handleSubmit.bind(this)

使用ES6的箭头方法就简单多了。它会自动维护正确的上下文(this)。

给setState传入一个方法

在上面的例子里有这么一行:

this.setState({ expanded: !this.state.expanded });
ログイン後にコピー

setState其实是异步的!React为了提高性能,会把多次调用的setState放在一起调用。所以,调用了setState之后state不一定会立刻就发生改变。

所以,调用setState的时候,你不能依赖于当前的state值。因为i根本不知道它是值会是神马。

解决方法:给setState传入一个方法,把调用前的state值作为参数传入这个方法。看看例子:

this.setState(prevState => ({ expanded: !prevState.expanded }))
ログイン後にコピー

感谢Austin Wood的帮助。

拆解组件

import React, { Component } from 'react'
import { observer } from 'mobx-react'
import { string, object } from 'prop-types'
import ExpandableForm from './ExpandableForm'
import './styles/ProfileContainer.css'
export default class ProfileContainer extends Component {
 state = { expanded: false }
 static propTypes = {
  model: object.isRequired,
  title: string
 }
 static defaultProps = {
  model: {
   id: 0
  },
  title: 'Your Name'
 }
 handleSubmit = (e) => {
  e.preventDefault()
  this.props.model.save()
 }
 handleNameChange = (e) => {
  this.props.model.changeName(e.target.value)
 }
 handleExpand = (e) => {
  e.preventDefault()
  this.setState(prevState => ({ expanded: !prevState.expanded }))
 }
 render() {
  const {
   model,
   title
  } = this.props
  return ( 
   
    

{title}

) } }
ログイン後にコピー

有多行的props的,每一个prop都应该单独占一行。就如上例一样。要达到这个目标最好的方法是使用一套工具:Prettier

装饰器(Decorator)

@observer
export default class ProfileContainer extends Component {
ログイン後にコピー

如果你了解某些库,比如mobx,你就可以使用上例的方式来修饰类组件。装饰器就是把类组件作为一个参数传入了一个方法。

装饰器可以编写更灵活、更有可读性的组件。如果你不想用装饰器,你可以这样:

class ProfileContainer extends Component {
 // Component code
}
export default observer(ProfileContainer)
ログイン後にコピー


闭包

尽量避免在子组件中传入闭包,如:

<input
 type="text"
 value={model.name}
 // onChange={(e) => { model.name = e.target.value }}
 // ^ Not this. Use the below:
 onChange={this.handleChange}
 placeholder="Your Name"/>
ログイン後にコピー

注意:如果input是一个React组件的话,这样自动触发它的重绘,不管其他的props是否发生了改变。

一致性检验是React最消耗资源的部分。不要把额外的工作加到这里。处理上例中的问题最好的方法是传入一个类方法,这样还会更加易读,更容易调试。如:


import React, { Component } from 'react'
import { observer } from 'mobx-react'
import { string, object } from 'prop-types'
// Separate local imports from dependencies
import ExpandableForm from './ExpandableForm'
import './styles/ProfileContainer.css'
// Use decorators if needed
@observer
export default class ProfileContainer extends Component {
 state = { expanded: false }
 // Initialize state here (ES7) or in a constructor method (ES6)
 // Declare propTypes as static properties as early as possible
 static propTypes = {
  model: object.isRequired,
  title: string
 }
 // Default props below propTypes
 static defaultProps = {
  model: {
   id: 0
  },
  title: 'Your Name'
 }
 // Use fat arrow functions for methods to preserve context (this will thus be the component instance)
 handleSubmit = (e) => {
  e.preventDefault()
  this.props.model.save()
 }
 handleNameChange = (e) => {
  this.props.model.name = e.target.value
 }
  handleExpand = (e) => {
  e.preventDefault()
  this.setState(prevState => ({ expanded: !prevState.expanded }))
 }
  render() {
  // Destructure props for readability
  const {
   model,
   title
  } = this.props
  return ( 
   
    // Newline props if there are more than two
    

{title}

{ model.name = e.target.value }} // Avoid creating new closures in the render method- use methods like below onChange={this.handleNameChange} placeholder="Your Name"/>

) } }
ログイン後にコピー

方法组件

这类组件没有state没有props,也没有方法。它们是纯组件,包含了最少的引起变化的内容。经常使用它们。

propTypes

import React from &#39;react&#39;
import { observer } from &#39;mobx-react&#39;
import { func, bool } from &#39;prop-types&#39;
import &#39;./styles/Form.css&#39;
ExpandableForm.propTypes = {
 onSubmit: func.isRequired,
 expanded: bool
}
// Component declaration
ログイン後にコピー

我们在组件的声明之前就定义了propTypes

分解Props和defaultProps


import React from &#39;react&#39;
import { observer } from &#39;mobx-react&#39;
import { func, bool } from &#39;prop-types&#39;
import &#39;./styles/Form.css&#39;
ExpandableForm.propTypes = {
 onSubmit: func.isRequired,
 expanded: bool,
 onExpand: func.isRequired
}
function ExpandableForm(props) {
 const formStyle = props.expanded ? {height: &#39;auto&#39;} : {height: 0}
 return (
  <form style={formStyle} onSubmit={props.onSubmit}>
   {props.children}
   <button onClick={props.onExpand}>Expand</button>
  </form>
 )
}
ログイン後にコピー

我们的组件是一个方法。它的参数就是props

また、クラスの前に exportdefault を必ず追加します。 (翻訳者注: ただし、redux を使用する場合は正しくない可能性があります)。

propTypes とdefaultProps

import React from &#39;react&#39;
import { observer } from &#39;mobx-react&#39;
import { func, bool } from &#39;prop-types&#39;
import &#39;./styles/Form.css&#39;
ExpandableForm.propTypes = {
 onSubmit: func.isRequired,
 expanded: bool,
 onExpand: func.isRequired
}
function ExpandableForm({ onExpand, expanded = false, children, onSubmit }) {
 const formStyle = expanded ? {height: &#39;auto&#39;} : {height: 0}
 return (
  <form style={formStyle} onSubmit={onSubmit}>
   {children}
   <button onClick={onExpand}>Expand</button>
  </form>
 )
}
ログイン後にコピー

propTypesdefaultProps は静的プロパティです。他の開発者がコードを読んだときにすぐに気付くことができるように、コンポーネント クラスのできるだけ早い段階でこれを定義します。それらはドキュメントとして機能します。

🎜 React 15.3.0 以降を使用している場合は、React.PropTypes を使用する代わりに、prop-types パッケージを個別に導入する必要があります。その他のコンテンツはここに移動します。 🎜🎜すべてのコンポーネントには prop タイプが必要です。 🎜🎜メソッド🎜🎜🎜🎜
const ExpandableForm = ({ onExpand, expanded, children }) => {
ログイン後にコピー
ログイン後にコピー
🎜🎜🎜🎜クラスコンポーネントで子コンポーネントにメソッドを渡すときは、正しい this を使用してメソッドが呼び出されることを確認する必要があります。これは通常、子コンポーネント this.handleSubmit.bind(this) に渡すときに行われます。 🎜🎜ES6 の arrow メソッドを使用する方がはるかに簡単です。正しいコンテキスト (this) が自動的に維持されます。 🎜🎜 setState にメソッドを渡す🎜🎜 上の例には、次の行があります: 🎜
import React from &#39;react&#39;
import { observer } from &#39;mobx-react&#39;
import { func, bool } from &#39;prop-types&#39;
import &#39;./styles/Form.css&#39;
ExpandableForm.propTypes = {
 onSubmit: func.isRequired,
 expanded: bool,
 onExpand: func.isRequired
}
function ExpandableForm({ onExpand, expanded = false, children, onSubmit }) {
 const formStyle = expanded ? {height: &#39;auto&#39;} : {height: 0}
 return (
  <form style={formStyle} onSubmit={onSubmit}>
   {children}
   <button onClick={onExpand}>Expand</button>
  </form>
 )
}
export default observer(ExpandableForm)
ログイン後にコピー
ログイン後にコピー
🎜setState は実際には非同期です!パフォーマンスを向上させるために、React は複数の setState 呼び出しをまとめて呼び出します。したがって、setState を呼び出した直後には状態が変化しない可能性があります。 🎜🎜 したがって、setState を呼び出すときは、現在の状態値に依存することはできません。価値が全く分からないからです。 🎜🎜解決策: メソッドを setState に渡し、このメソッドのパラメーターとして呼び出す前に状態値を渡します。例を見てみましょう: 🎜
import React from &#39;react&#39;
import { observer } from &#39;mobx-react&#39;
import { func, bool } from &#39;prop-types&#39;
// Separate local imports from dependencies
import &#39;./styles/Form.css&#39;
// Declare propTypes here, before the component (taking advantage of JS function hoisting)
// You want these to be as visible as possible
ExpandableForm.propTypes = {
 onSubmit: func.isRequired,
 expanded: bool,
 onExpand: func.isRequired
}
// Destructure props like so, and use default arguments as a way of setting defaultProps
function ExpandableForm({ onExpand, expanded = false, children, onSubmit }) {
 const formStyle = expanded ? { height: &#39;auto&#39; } : { height: 0 }
 return (
  <form style={formStyle} onSubmit={onSubmit}>
   {children}
   <button onClick={onExpand}>Expand</button>
  </form>
 )
}
// Wrap the component instead of decorating it
export default observer(ExpandableForm)
ログイン後にコピー
ログイン後にコピー
🎜Austin Wood の協力に感謝します。 🎜🎜コンポーネントを逆アセンブルします🎜
<p id="lb-footer">
 {props.downloadMode && currentImage && !currentImage.video && currentImage.blogText
 ? !currentImage.submitted && !currentImage.posted
 ? <p>Please contact us for content usage</p>
  : currentImage && currentImage.selected
   ? <button onClick={props.onSelectImage} className="btn btn-selected">Deselect</button>
   : currentImage && currentImage.submitted
    ? <button className="btn btn-submitted" disabled>Submitted</button>
    : currentImage && currentImage.posted
     ? <button className="btn btn-posted" disabled>Posted</button>
     : <button onClick={props.onSelectImage} className="btn btn-unselected">Select post</button>
 }
</p>
ログイン後にコピー
ログイン後にコピー
🎜 props が複数行ある場合、各プロパティは別の行を占める必要があります。上の例と同じです。この目標を達成するための最良の方法は、一連のツール Prettier を使用することです。 🎜🎜🎜デコレーター🎜
<p id="lb-footer">
 {
  (() => {
   if(downloadMode && !videoSrc) {
    if(isApproved && isPosted) {
     return <p>Right click image and select "Save Image As.." to download</p>
    } else {
     return <p>Please contact us for content usage</p>
    }
   }
   // ...
  })()
 }
</p>
ログイン後にコピー
ログイン後にコピー
🎜mobx などのライブラリを知っている場合は、上記の例を使用してクラス コンポーネントを装飾できます。デコレータは、クラス コンポーネントをパラメータとして渡すメソッドです。 🎜🎜デコレータを使用すると、より柔軟で読みやすいコンポーネントを作成できます。デコレータを使用したくない場合は、次のようにすることができます: 🎜rrreee🎜🎜クロージャ🎜🎜次のような子コンポーネントでクロージャを渡さないようにしてください: 🎜rrreee🎜注: If input< /code> が React コンポーネントの場合、他のプロパティが変更されたかどうかに関係なく、再描画が自動的にトリガーされます。 🎜🎜整合性チェックは React で最もリソースを消費する部分です。ここで余分な作業を追加しないでください。上記の例の問題を処理する最善の方法は、クラス メソッドを渡すことです。これにより、読みやすく、デバッグが容易になります。例: 🎜🎜🎜🎜rrreee🎜<strong>メソッド コンポーネント </strong>🎜🎜 このタイプのコンポーネントには状態、プロパティ、メソッドがありません。これらは最小限の変更を含む純粋なコンポーネントです。頻繁に使用してください。 🎜🎜propTypes🎜rrreee🎜 コンポーネントの宣言の前に <code>propTypes を定義します。 🎜🎜Props とdefaultProps を分解します🎜🎜🎜🎜rrreee🎜私たちのコンポーネントはメソッドです。そのパラメータは props です。このコンポーネントは次のように拡張できます: 🎜🎜🎜🎜rrreee🎜🎜🎜

现在我们也可以使用默认参数来扮演默认props的角色,这样有很好的可读性。如果expanded没有定义,那么我们就把它设置为false

但是,尽量避免使用如下的例子:

const ExpandableForm = ({ onExpand, expanded, children }) => {
ログイン後にコピー
ログイン後にコピー

看起来很现代,但是这个方法是未命名的。

如果你的Babel配置正确,未命名的方法并不会是什么大问题。但是,如果Babel有问题的话,那么这个组件里的任何错误都显示为发生在 <>里的,这调试起来就非常麻烦了。

匿名方法也会引起Jest其他的问题。由于会引起各种难以理解的问题,而且也没有什么实际的好处。我们推荐使用function,少使用const

装饰方法组件

由于方法组件没法使用装饰器,只能把它作为参数传入别的方法里。


import React from &#39;react&#39;
import { observer } from &#39;mobx-react&#39;
import { func, bool } from &#39;prop-types&#39;
import &#39;./styles/Form.css&#39;
ExpandableForm.propTypes = {
 onSubmit: func.isRequired,
 expanded: bool,
 onExpand: func.isRequired
}
function ExpandableForm({ onExpand, expanded = false, children, onSubmit }) {
 const formStyle = expanded ? {height: &#39;auto&#39;} : {height: 0}
 return (
  <form style={formStyle} onSubmit={onSubmit}>
   {children}
   <button onClick={onExpand}>Expand</button>
  </form>
 )
}
export default observer(ExpandableForm)
ログイン後にコピー
ログイン後にコピー

只能这样处理:export default observer(ExpandableForm)

这就是组件的全部代码:


import React from &#39;react&#39;
import { observer } from &#39;mobx-react&#39;
import { func, bool } from &#39;prop-types&#39;
// Separate local imports from dependencies
import &#39;./styles/Form.css&#39;
// Declare propTypes here, before the component (taking advantage of JS function hoisting)
// You want these to be as visible as possible
ExpandableForm.propTypes = {
 onSubmit: func.isRequired,
 expanded: bool,
 onExpand: func.isRequired
}
// Destructure props like so, and use default arguments as a way of setting defaultProps
function ExpandableForm({ onExpand, expanded = false, children, onSubmit }) {
 const formStyle = expanded ? { height: &#39;auto&#39; } : { height: 0 }
 return (
  <form style={formStyle} onSubmit={onSubmit}>
   {children}
   <button onClick={onExpand}>Expand</button>
  </form>
 )
}
// Wrap the component instead of decorating it
export default observer(ExpandableForm)
ログイン後にコピー
ログイン後にコピー

条件判断

某些情况下,你会做很多的条件判断:


<p id="lb-footer">
 {props.downloadMode && currentImage && !currentImage.video && currentImage.blogText
 ? !currentImage.submitted && !currentImage.posted
 ? <p>Please contact us for content usage</p>
  : currentImage && currentImage.selected
   ? <button onClick={props.onSelectImage} className="btn btn-selected">Deselect</button>
   : currentImage && currentImage.submitted
    ? <button className="btn btn-submitted" disabled>Submitted</button>
    : currentImage && currentImage.posted
     ? <button className="btn btn-posted" disabled>Posted</button>
     : <button onClick={props.onSelectImage} className="btn btn-unselected">Select post</button>
 }
</p>
ログイン後にコピー
ログイン後にコピー


这么多层的条件判断可不是什么好现象。

有第三方库JSX-Control Statements可以解决这个问题。但是与其增加一个依赖,还不如这样来解决:

<p id="lb-footer">
 {
  (() => {
   if(downloadMode && !videoSrc) {
    if(isApproved && isPosted) {
     return <p>Right click image and select "Save Image As.." to download</p>
    } else {
     return <p>Please contact us for content usage</p>
    }
   }
   // ...
  })()
 }
</p>
ログイン後にコピー
ログイン後にコピー

使用大括号包起来的IIFE,然后把你的if表达式都放进去。返回你要返回的组件。

相关推荐:

React组件的性能优化方法

关于React组件项目实践

React Native如何实现图片查看组件


以上がReact コンポーネント プロジェクトの作成に関する実践的な分析の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

Outlook がカレンダーにイベントを自動的に追加しないようにする方法 Outlook がカレンダーにイベントを自動的に追加しないようにする方法 Feb 26, 2024 am 09:49 AM

電子メール マネージャー アプリケーションとして、Microsoft Outlook を使用すると、イベントや予定をスケジュールできます。 Outlook アプリケーションでこれらのアクティビティ (イベントとも呼ばれます) を作成、管理、追跡するためのツールを提供することで、組織的な状態を維持できるようになります。ただし、Outlook の予定表に不要なイベントが追加される場合があり、ユーザーが混乱したり、予定表にスパムが送信されたりすることがあります。この記事では、Outlook が予定表にイベントを自動的に追加しないようにするために役立つさまざまなシナリオと手順を説明します。 Outlook イベント – 簡単な概要 Outlook イベントには複数の目的があり、次のような多くの便利な機能があります。 カレンダーの統合: Outlook 内

Dreamweaver CMS ステーションのグループ練習の共有 Dreamweaver CMS ステーションのグループ練習の共有 Mar 18, 2024 am 10:18 AM

Dream Weaver CMS Station グループ実践共有 近年、インターネットの急速な発展に伴い、Webサイト構築の重要性がますます高まっています。複数の Web サイトを構築する場合、サイト グループ テクノロジは非常に効果的な方法となっています。数多くの Web サイト構築ツールの中でも、Dreamweaver CMS は、その柔軟性と使いやすさにより、多くの Web サイト愛好家にとって最初の選択肢となっています。この記事では、Dreamweaver CMS ステーション グループに関するいくつかの実践的な経験と、いくつかの具体的なコード例を共有し、ステーション グループ テクノロジを研究している読者に何らかの助けとなることを願っています。 1. Dreamweaver CMS ステーション グループとは何ですか?ドリームウィーバーCMS

PHP、Vue、React: 最適なフロントエンド フレームワークを選択するには? PHP、Vue、React: 最適なフロントエンド フレームワークを選択するには? Mar 15, 2024 pm 05:48 PM

PHP、Vue、React: 最適なフロントエンド フレームワークを選択するには?インターネット技術の継続的な発展に伴い、フロントエンド フレームワークは Web 開発において重要な役割を果たしています。 PHP、Vue、React は 3 つの代表的なフロントエンド フレームワークであり、それぞれに独自の特徴と利点があります。使用するフロントエンド フレームワークを選択するとき、開発者はプロジェクトのニーズ、チームのスキル、個人の好みに基づいて情報に基づいた決定を下す必要があります。この記事では、PHP、Vue、React の 3 つのフロントエンド フレームワークの特徴と用途を比較します。

PHP コーディングの実践: Goto ステートメントの代替手段の拒否 PHP コーディングの実践: Goto ステートメントの代替手段の拒否 Mar 28, 2024 pm 09:24 PM

PHP コーディングの実践: Goto ステートメントの代替手段の使用の拒否 近年、プログラミング言語の継続的な更新と反復により、プログラマーはコーディング仕様とベスト プラクティスにより多くの注意を払い始めています。 PHP プログラミングでは、制御フロー ステートメントとして goto ステートメントが長い間存在していましたが、実際のアプリケーションではコードの可読性と保守性の低下につながることがよくあります。この記事では、開発者が goto ステートメントの使用を拒否し、コードの品質を向上させるのに役立ついくつかの代替案を紹介します。 1. なぜ goto ステートメントの使用を拒否するのですか?まず、その理由を考えてみましょう

Java フレームワークとフロントエンド React フレームワークの統合 Java フレームワークとフロントエンド React フレームワークの統合 Jun 01, 2024 pm 03:16 PM

Java フレームワークと React フレームワークの統合: 手順: バックエンド Java フレームワークをセットアップします。プロジェクト構造を作成します。ビルドツールを設定します。 React アプリケーションを作成します。 REST API エンドポイントを作成します。通信メカニズムを構成します。実際のケース (SpringBoot+React): Java コード: RESTfulAPI コントローラーを定義します。 React コード: API によって返されたデータを取得して表示します。

Struts フレームワークの原則と実践についての深い議論 Struts フレームワークの原則と実践についての深い議論 Feb 18, 2024 pm 06:10 PM

Struts フレームワークの原理分析と実践的な調査 JavaWeb 開発で一般的に使用される MVC フレームワークとして、Struts フレームワークは優れた設計パターンとスケーラビリティを備えており、エンタープライズ レベルのアプリケーション開発で広く使用されています。この記事では、Struts フレームワークの原理を分析し、読者がフレームワークをよりよく理解して適用できるように、実際のコード例を使用してそれを検討します。 1. Struts フレームワークの原理の分析 1. MVC アーキテクチャ Struts フレームワークは MVC (Model-View-Con) に基づいています。

Golang を使用したトラフィック管理のベスト プラクティス Golang を使用したトラフィック管理のベスト プラクティス Mar 07, 2024 am 08:27 AM

Golang は、Web サービスやアプリケーションの構築に広く使用されている強力で効率的なプログラミング言語です。ネットワーク サービスでは、トラフィック管理は重要な部分であり、ネットワーク上のデータ送信を制御および最適化し、サービスの安定性とパフォーマンスを確保するのに役立ちます。この記事では、Golang を使用したトラフィック管理のベスト プラクティスを紹介し、具体的なコード例を示します。 1. 基本的なトラフィック管理に Golang の net パッケージを使用する Golang の net パッケージは、ネットワーク データを処理する方法を提供します。

DreamWeaver CMS のセカンダリディレクトリを開けない原因の分析 DreamWeaver CMS のセカンダリディレクトリを開けない原因の分析 Mar 13, 2024 pm 06:24 PM

タイトル: DreamWeaver CMS のセカンダリディレクトリを開けない原因と解決策の分析 Dreamweaver CMS (DedeCMS) は、さまざまな Web サイトの構築に広く使用されている強力なオープンソースのコンテンツ管理システムです。ただし、Web サイトの構築中に、セカンダリ ディレクトリを開けない状況が発生し、Web サイトの通常の動作に問題が発生することがあります。この記事では、セカンダリ ディレクトリを開けない考えられる理由を分析し、この問題を解決するための具体的なコード例を示します。 1. 考えられる原因分析: 疑似静的ルール構成の問題: 使用中

See all articles