vue安装+测试

news/2024/7/8 2:40:43 标签: vue.js, 前端, javascript

1.下载node.js
在浏览器中打开nodejs官网https://nodejs.org/zh-cn/ ,选择需要的版本

2.检查nodejs是否安装成功
打开cmd,输入命令 node -v

PS C:\Users\neuer> node -v
v20.15.0

3.安装cnpm
遇到npm ERR! code CERT_HAS_EXPIRED问题

清除npm缓存
npm cache clean --force
取消ssl验证:
npm config set strict-ssl false
再不行的话试试更换npm镜像源:
npm config set registry http://registry.cnpmjs.org
npm config set registry http://registry.npm.taobao.org

最后执行,下载cnpm
npm install -g cnpm --registry=https://registry.npm.taobao.org
查看安装版本:
cnpm -v

4.安装vue-cli (vue脚手架)
通过cnpm全局安装vue脚手架,运行命令

cnpm install --global vue-cli
在cmd中输入vue -V (注意:V是大写V)
vue -V 
结果:
PS C:\Users\neuer> vue -V
2.9.6

5.创建新项目
在VScode 中使用vue-cli 创建项目时报错 vue : 无法加载文件 C:\Users\…\npm\vue.ps1,因为在此系统上禁止运行脚本。

vue init webpack MyPortalProject

在这里插入图片描述
解决办法:
打开终端管理员,
在这里插入图片描述

6.创建新项目

PS D:\npy-study\study_memory\vue\learn> vue init webpack MyPortalProject

? Project name myportal
? Project description A Vue.js project
? Author neuerliu <181870134@smail.nju.edu.cn>
? Vue build standalone
? Install vue-router? Yes
? Use ESLint to lint your code? No
? Set up unit tests No
? Setup e2e tests with Nightwatch? No
? Should we run `npm install` for you after the project has been c
reated? (recommended) npm

   vue-cli · Generated "MyPortalProject".


# Installing project dependencies ...
# ========================

npm warn deprecated stable@0.1.8: Modern JS already guarantees Arr

在这里插入图片描述
7.运行项目
在终端运行

cd MyPortalProject
然后运行命令 npm run dev,启动项目看看最终效果吧

 npm run dev

在这里插入图片描述
在这里插入图片描述
8.安装element-ui

cnpm i element-ui -S

在这里插入图片描述

9.在项目中使用element-ui

  • 在main.js中引入element组件
/*引入如下组件*/
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);
  • main.js修改后的代码为
javascript">// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
/*引入element组件*/
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);
 
Vue.config.productionTip = false
 
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
  • 修改组件HelloWorld.vue代码如下
<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
    <el-row>
      <el-button>默认按钮</el-button>
      <el-button type="primary">主要按钮</el-button>
      <el-button type="success">成功按钮</el-button>
      <el-button type="info">信息按钮</el-button>
      <el-button type="warning">警告按钮</el-button>
      <el-button type="danger">危险按钮</el-button>
    </el-row>
  </div>
</template>
 
<script>
export default {
  name: "HelloWorld",
  data() {
    return {
      msg: "使用element-ui测试",
    };
  },
};
</script>
 
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1,
h2 {
  font-weight: normal;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>

http://www.niftyadmin.cn/n/5536176.html

相关文章

Hadoop-11-MapReduce JOIN 操作的Java实现 Driver Mapper Reducer具体实现逻辑 模拟SQL进行联表操作

章节内容 上一节我们完成了&#xff1a; MapReduce的介绍Hadoop序列化介绍Mapper编写规范Reducer编写规范Driver编写规范WordCount功能开发WordCount本地测试 背景介绍 这里是三台公网云服务器&#xff0c;每台 2C4G&#xff0c;搭建一个Hadoop的学习环境&#xff0c;供我学…

鸿蒙开发HarmonyOS NEXT (三) 熟悉ArkTs

一、自定义组件 1、自定义组件 自定义组件&#xff0c;最基础的结构如下&#xff1a; Component struct Header {build() {} } 提取头部标题部分的代码&#xff0c;写成自定义组件。 1、新建ArkTs文件&#xff0c;把Header内容写好。 2、在需要用到的地方&#xff0c;导入…

工业智能网关的作用有哪些?工业智能网关与传统网关的主要区别-天拓四方

工业智能网关是一种专为工业环境设计的网络设备&#xff0c;具备数据采集、传输、协议转换以及边缘计算等功能。它作为连接工业设备与互联网的关键枢纽&#xff0c;不仅实现了工业设备的互联互通&#xff0c;还通过对采集到的数据进行实时分析&#xff0c;为工业生产的智能化管…

Git指令

一 参考&#xff1a;https://zhuanlan.zhihu.com/p/389814854 1.clone远程仓库 git clone https://git.xiaojukeji.com/falcon-mg/dagger.git 2.增加当前子目录下所有更改过的文件至index git add . 3.提交并备注‘xxx’ git commit -m ‘xxx’ 4.显示本地分支 git branch 5.显…

FPGA DDR4读写实验(1)

DDR4 SDRAM&#xff08;Double-Data-Rate Fourth Generation Synchronous Dynamic Random Access Memory&#xff0c;简称为 DDR4 SDRAM&#xff09;&#xff0c;是一种高速动态随机存取存储器&#xff0c;它属于 SDRAM 家族的存储器产品&#xff0c;提供了相较于 DDR3 SDRAM 更…

以创新思维驱动下的盲盒小程序:重塑用户体验

一、引言 在数字化浪潮的推动下&#xff0c;小程序以其便捷、高效、无需下载安装的特性&#xff0c;迅速成为移动互联网的新宠。其中&#xff0c;盲盒小程序以其独特的玩法和惊喜感&#xff0c;吸引了大量用户的关注和参与。然而&#xff0c;随着市场竞争的加剧&#xff0c;如…

龙芯杯个人赛记录

惊觉8.5就是个人赛ddl&#xff0c;啥都不会和没做&#xff0c;打算对着《cpu设计实战》和B站视频走。

Python爬虫教程第0篇-写在前面

为什么写这个系列 最近开发了个Python爬虫的脚本&#xff0c;去抢一个名额&#xff0c;结果是程序失败了&#xff0c;中间有各种原因&#xff0c;终究还是准备不足的问题。我想失败的经验或许也可贵&#xff0c;便总结一下当初从0开始学Python&#xff0c;一步步去写Python脚本…