首页 > 其他分享 >react小知识

react小知识

时间:2022-11-22 16:36:28浏览次数:43  
标签:npm 知识 react install import 安装 native

安装以来;依赖:下载node.js
node.js
淘宝镜像加快安装速度:
npm config set registry https://registry.npm.taobao.org
npm config get registry
npm i nrm -g


webpack
全局安装:npm install -g webpack
局部安装:npm install webpack --save-dev
卸载
npm uninstall webpack -g ,//没试
 npm uninstall webpack

vue
1.安装vue脚手架
(1)安装淘宝镜像:npm config set registry http://registry.npm.taobao.org
(2)创建脚手架,只需创建一次:npm install -g @vue/cli
(3)创建项目:vue create vue_test(项目名称)
(4)运行:npm run serve


第一次运行vue需要运行
npm install --legacy-peer-deps  //npm安装,忽略其他(用于vue启动项目)




react
1.创建react脚手架(初始化项目):
npx create-react-app react basic     // npx临时安装包,create-react-app是react脚手架名称,react basic表示项目名称

需要在src里新建四个文件夹:assets用来存放资源(图片,字体图标)、components用来存放公共组件、page存放页面的js文件、untils工具型函数

要重新引入:import React from "react"
import  ReactDOM  from "react-dom"
2.启动项目
yarn start  or   npm start

3.npm i prop-types   props校验安装的包
导入props校验包   import PropTypes from "prop-types"

4.React路由的基本使用
安装路由包: npm install react-router-dom
导入路由包:import { BrowserRouter as Router,Route,Link} from 'react-router-dom' ;
使用Router组件包裹整个应用
使用Link组件作为导航菜单(路由入口)
使用Route组件作为导航菜单(路由出口)

5.导入图片
import img from '路径'  //图片文件夹要放在src包文件夹里
使用图片:<img src={img} alt='  ' />

6.组件库   https://mobile.ant.design
使用指南:(1.)安装组件库  npm install --save antd-mobile
                (2.)在app.js中导入要使用的组件,直接引入组件即可,antd-mobile 会自动为你加载 css 样式文件:   import { Button } from 'antd-mobile'   
                  (3.)在页面中渲染
                (4.)安装路由组件,导入路由组件


React Native
1.(1.)全局安装react-native脚手架:npm install -g react-native-cli
(2.)安装yarn:npm install -g yarn
(3.)创建React native 项目 (限制版本):npx react-native init 项目名称 --version  0.64.0     /0.68.2
(4.)运行react native项目:npm run start
         启动Android模拟器:react-native run-android
(5.)安裝字体图标库:http://reactnative.directory
         命令:npm install --save react-native-vector-icons
                  npx react-native link react-native-vector-icons
          引入:import icon from 'react-native-vector-icons'  要使用哪个名称就import icon from 'react-native-vector-icons/图标名称
(6.)react-navigation路由
        a.使用 NPM 安装:npm install --save react-navigation
       使用 Yarn 安装:yarn add react-navigation
       b.要自动进行所有必要的更改,请在项目的根文件夹中运行:npx rnn-link


2.react-native报错No Babel config file detected for xxx
   可以尝试在.eslintrc文件中添加以下内容:
      "parser":"@babel/eslint-parser",
      "parserOptions":{"requireConfigFile":false}
3.报错Parsing error: This experimental syntax requires enabling one of the following parser plugin(s): "jsx", "flow", "typescript". (6:4)eslint
(1.)安装启用 babel 正确解析 jsx 所需的依赖项:
     npm install --save-dev @babel/preset-react
(2.) 配置 Babel,.babelrc项目根目录下的文件:
         "@babel/preset-react"
(3.)指定解析器.eslintrc.json(因此您的控制台和 VSCode 将使用相同的) - 此处显示完整的 eslintrc:
{
    "parser": "@babel/eslint-parser",
    "settings": {
        "react": {
            "version": "detect"
        }
    },
    "env": {
        "browser": true,
        "es2021": true
    },
    "extends": [
        "plugin:react/recommended",
        "standard",
        "plugin:react/jsx-runtime",
        "plugin:testing-library/react",
        "plugin:jest/all"
    ],
    "parserOptions": {
        "sourceType": "module"
    },
    "rules": {}
}



Android:
adb shell input keyevent 82

 

标签:npm,知识,react,install,import,安装,native
From: https://www.cnblogs.com/hs20011205/p/16915524.html

相关文章

  • vue-ref,reactive,toRefs,toRef总结
    总结:ref,reactive,toRefs,toRef方法响应式引用的原理:通过proxy对数据进行封装,当数据变化时,触发模版等内容的更新。一、ref:作用:接受一个内部值并返回响应式且可变的ref对象......
  • 电容知识
    电解电容在铝、钛等金属的表面,采用阳极氧化法生成薄层氧化物作为电介质,以电解质作为阴极而构成。工作介质很薄10-2~10-3微米之间。分类:有极性电解电容器、无极性电解电......
  • 图像处理技术:图像获取 ----- 三、MATLAB基础知识
    1.MATLAB的数据种类、文件类型、操作符数据种类    文件类型:            操作符:           ......
  • python基础知识点
    目录字典列表字典a={}a['you']=['a','b']a['me']=['c','d']print(a)输出结果:{'you':['a','b'],'me':['c','d']}列表print([2]+[3])输出结果......
  • React 学习笔记之一 - ES6 基础
    1.1let及const1.1.1let命令用var声明变量有变量提升的情况。1console.log(a);2vara=1; 如果没有第二行的声明,那么会看到“aisnotdefined......
  • create-react-app build without source map file All In One
    create-react-appbuildwithoutsourcemapfileAllInOnecrasourcemapsolutions.envGENERATE_SOURCEMAP=false#https://create-react-app.dev/docs/addi......
  • WordPress 多表情文章投票/心情评价插件 DW Reactions
    今天推荐的DWReactions是一款非常漂亮的WordPress多表情文章投票插件,它和Facebook的一个新功能非常相似,允许访客对每篇博客文章表达多种情感。看看下面的图片,是不是......
  • React类式组件和函数式组件的区别
    React类式组件和函数式组件的区别有哪些呢?  主要要以下几个区别:(1)语法不同、设计思想不同(2)生命周期、状态变量(3)复用性:(4)优缺点一、语法不同、设计思想不同函数式组件......
  • angular 预备知识
    安装1先安装node.js2安装淘宝cnpm第一种:直接安装cnpm安装淘宝提供的cnpm,并更改服务器地址为淘宝的国内地址,命令:npminstall-gcnpm--registry=https://registry......
  • 互斥锁及线程相关知识
    今日内容概要多进程实现TCP服务端并发互斥锁线程相关基础知识GIL全局解释器锁event事件进程池与线程池协程今日内容详细多进程实现TCP服务端并发多进程实现TCP......