npm介绍以及简单的使用

本文介绍了npm和cnpm这两个Node.js的包管理工具。详细讲述了npm的安装、版本查看、更新、安装模块、查看安装信息、卸载和更新模块以及搜索模块的基本操作。同时,针对国内用户,讲解了cnpm的安装和使用,作为npm的快速替代方案。
摘要由CSDN通过智能技术生成

目录

一、NPM相关

1.npm安装

2.查看版本

3.更新npm命令:

4.使用npm安装模块

5.查看安装信息

6.卸载模块

7.更新模块

8.搜索模块

二、cnpm相关

1.cnpm安装

2.cnpm安装模块


NPM是随同NodeJS一起安装的包管理工具;

通过两个部分分别介绍npm及cnpm

一、NPM相关

1.npm安装

命令:

npm install

2.查看版本

安装完nodejs后,可以通过cmd命令“npm -v”查看版本;

npm -v

效果如下图:

3.更新npm命令:

sudo npm install npm -g

4.使用npm安装模块

通用命令:

npm install 模块名

使用 npm 命令安装 Node.js web框架模块 express:

npm install express

5.查看安装信息

命令:

npm list -g

查看模块安装信息,命令:

npm list 模块名

6.卸载模块

卸载npm模块命令:

npm uninstall 模块名

7.更新模块

命令:

npm uninstall 模块名

8.搜索模块

命令:

npm search 模块名

二、cnpm相关

由于国内直接使用 npm 的官方镜像非常慢,所以推荐使用淘宝 NPM 镜像。

1.cnpm安装

命令:

npm install -g cnpm --registry=https://registry.npmmirror.com

2.cnpm安装模块

安装完成后,可以使用cnpm 命令行工具代替默认的 npm:

cnpm install 模块名

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Pinia 是 Vue.js 的状态管理库,它用于管理组件间共享的状态。其设计灵感来自于 Vuex 4,但更加简洁和模块化。Pinia 可以被看作是 Vuex 的替代方案,但其核心思想是提供一个简单、轻量、但同时具备Vuex核心特性的状态管理解决方案。 使用 Pinia 主要包含以下几个步骤: 1. 安装 Pinia: 你可以通过 npm 或 yarn 来安装 Pinia。 ```bash npm install pinia # 或者 yarn add pinia ``` 2. 创建一个 Pinia store: 在你的 Vue 应用中,你可以创建一个或多个 store 来管理状态。每个 store 都是一个带有状态(state)、getter、actions 的对象。 ```javascript import { defineStore } from 'pinia'; export const useCounterStore = defineStore('counter', { state: () => ({ count: 0, }), actions: { increment() { this.count++; }, }, getters: { doubleCount: (state) => state.count * 2, }, }); ``` 3. 在组件中使用 store: 在 Vue 组件中,你可以通过 `useStore` 方法来访问和操作 store 中的状态和方法。 ```javascript <template> <div> <p>Count: {{ store.count }}</p> <button @click="store.increment">Increment</button> </div> </template> <script> import { useCounterStore } from '@/stores/counter'; export default { setup() { const store = useCounterStore(); return { store }; }, }; </script> ``` 4. 启用 Pinia: 最后,需要将 Pinia 添加到 Vue 应用中。 ```javascript import { createApp } from 'vue'; import { createPinia } from 'pinia'; import App from './App.vue'; import { useCounterStore } from '@/stores/counter'; const app = createApp(App); const pinia = createPinia(); app.use(pinia); app.mount('#app'); ``` 通过以上步骤,你就可以在 Vue 应用中使用 Pinia 来管理状态了。Pinia 提供了响应式的状态管理,使得状态的跟踪和调试更加方便。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

只管码

感谢您的打赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值