简体   繁体   English

react.js 中的依赖到底是什么意思?

[英]What exactly means dependency in react.js?

I am studying React.js., and I have started by setting the project folders to try some codes.我正在研究 React.js,我已经开始设置项目文件夹来尝试一些代码。 But, some terms are confusing me as a beginner.但是,有些术语让我作为初学者感到困惑。 One of them is "dependency."其中之一是“依赖”。 When I search for it, the result is only related to dependency injection stuff, but what is the "dependency" itself?当我搜索它时,结果只与依赖注入有关,但“依赖”本身是什么?

A dependency is some third-party code that your application depends on.依赖项是您的应用程序所依赖的一些第三方代码。 Just like a child depends on its parent, your application depends on other people's code.就像一个孩子依赖于它的父母一样,你的应用程序依赖于其他人的代码。 A piece of code becomes a true dependency when your own application cannot function without it.当你自己的应用程序没有它就不能 function 时,一段代码就变成了真正的依赖。

If you want to look at the dependencies you're using, you can find them in the package.json file under the dependencies key.如果您想查看正在使用的依赖项,可以在dependencies项键下的package.json文件中找到它们。

Well, dependencies are those things that you need to install and import for doing specific things, for example, if you want to add routing(moving from one page to another which changes your URL) in your react project then you need to install react-router-dom dependency by doing好吧,依赖项是您需要安装和导入以执行特定操作的那些东西,例如,如果您想在您的 react 项目中添加路由(从一个页面移动到另一个页面,这会更改您的 URL),那么您需要安装 react- router-dom 依赖做

npm install react-router-dom

A dependency is just a package that your project uses.依赖项只是您的项目使用的 package。

Very few javascript projects are entirely self-contained.很少有 javascript 项目是完全独立的。 When your project needs code from other projects in order to do its thing, those other projects are "dependencies";当您的项目需要其他项目的代码来完成它的工作时,那些其他项目就是“依赖项”; your project depends on them to run.您的项目依赖于它们来运行。

When you install third-party packages via npm install <package> , you're adding a dependency.当您通过npm install <package>第三方软件包时,您正在添加一个依赖项。

Your project's package.json file includes a list of your project's dependencies.项目的package.json文件包含项目依赖项的列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM