npm切换淘宝镜像「建议收藏」

(21) 2023-04-05 18:34

Hi,大家好,我是编程小6,很荣幸遇见你,我把这些年在开发过程中遇到的问题或想法写出来,今天说一说npm切换淘宝镜像「建议收藏」,希望能够帮助你!!!。

1.npm i nrm -g

2.nrm Ls

3.nrm use taobao

下面是安装yarn命令

npm i yarn -g

重新现在依赖包 npm i

解包 npm run eject

卸载某个包 用 npm uni

react项目运行命令为 yarn start

vue项目运行命令为 yarn serve

项目都需要下载axios,官网为 axios中文文档|axios中文网 | axios欢迎使用 axios,本文档将帮助您快速上手。(troubleshooting.html) 中的解答, 什么是 axios?Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中。 axios Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中。 特性 从浏览器中创建 XMLHttpRequests 从 nodenpm切换淘宝镜像「建议收藏」_https://bianchenghao6.com/blog__第1张http://www.axios-js.com/zh-cn/docs/

 npm install axios

如果下载特定版本需要在后面加@版本号

还需要下载路由react-router-dom

npm install react-router-dom --save

二、在src目录下新建一个Router.js文件用来配置路由

import Page1 from './pages/Page1'
import Page2 from './pages/Page2'
import React, { Component } from 'react'
import { Route, Switch, withRouter, BrowserRouter } from 'react-router-dom'
class Router extends Component {
  constructor(props) {
    super(props)
    this.state = {
    }
  }

  render() {
    return (
      <BrowserRouter>
        <Switch>
          <Route exact path="/" component={withRouter(Page1)} />
          <Route exact path="/page2" component={withRouter(Page2)} />
        </Switch>
      </BrowserRouter>
    )
  }
}
export default Router

三、修改index.js文件

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
// import App from './App';
import Router from './Router'
import * as serviceWorker from './serviceWorker';

ReactDOM.render(<Router />, document.getElementById('root'));

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister();

 

四、在页面们中的使用

下边的那种写法都可以,前两种传参的话会暴露在地址栏,第三种比较优雅,不会暴露在地址栏,但是浏览器刷新后参数就没了,需要配合存储使用。

this.props.history.push('/page2')
this.props.history.push({pathname:'/page2'}) 
this.props.history.push({pathname:"/page2",state : { id : '111' }});

五、路由传参

this.props.history.push('/page2/' + 666 + '')
this.props.history.push({pathname:'/'}) 

上边的写法传参就是要在后边拼接
不推荐用上边的写法传参,改变URL,可能导致路由失败

this.props.history.push({pathname:"/page2",state : { id : '111' }});

获取数据:this.props.location.state.id

 

 

上一篇

已是最后文章

下一篇

已是最新文章

发表回复