01 Vue3基础入门

目录

Vue3基础入门

Vue代码编写风格

前提条件

创建Vue项目

开发环境

项目文件说明

Vue代码编写风格

  • 选项式API --> vue2
javascript 复制代码
<script>
 export default {
   data() {
     return {
       count: 0
     }
   },
   methods: {
     increment() {
       this.count++
     }
   },
   mounted() {
     console.log(`The initial count is ${this.count}.`)
   }
 }
 </script>
 ​
 <template>
   <button @click="increment">Count is: {{ count }}</button>
 </template>
  • 组合式API --> vue3
javascript 复制代码
 <script setup>
 import { ref, onMounted} from 'vue'
 const count = ref(0)
 function increment() {
   count.value++
 }
 onMounted(() => {
   console.log(`The initial count is ${count.value}.`)
 })
 </script>
 ​
 <template>
   <button @click="increment">Count is: {{ count }}</button>
 </template>

前提条件

  • 安装15.0或更高版本的Node.js

创建Vue项目

  • cd进入你的项目所在文件夹
bash 复制代码
 npm init vue@latest
  • 这个指令将会安装并执行create-vue,它是Vue官方的项目脚手架工具。你将会看到一些诸如TypeScript和测试支持之类的可选功能提示。
bash 复制代码
 √ project name: ... <your-project-name>
 √ Add TypeScript? ... No / Yes
 √ Add JSX Support? ... No / Yes
 √ Add Vue Router for single Page Application development? ... No / Yes
 √ Add Pinia for state management? ... No / Yes
 √ Add Vitest for Unit testing? ... No / Yes
 √ Add Cypress for both Unit and End-to-End testing? ... No / Yes
 √ Add ESLint for code quality? ... No / Yes
 √ Add Prettier for code formatting? ... No / Yes
 ​
 scaffolding project in ./<your-project-name>...
 Done.
  • 根据提示,继续运行,值得注意的是,npm可用cnpm,因为cnpm是npm的国内镜像,能加速下载

cnpm 的安装与使用\] https://developer.aliyun.com/article/1599824 ```bash cd vue-base npm install npm run dev ``` * 浏览器打开这个网址,说明创建成功 ![](https://i-blog.csdnimg.cn/direct/7e5a9ea11fbc43a6a742b82a23780fb1.png) ![](https://i-blog.csdnimg.cn/direct/6395c0b79b9d4607ad83692a324bcf9e.png) ### 开发环境 推荐的IDE配置是`Visual Studio Code` + `Volar`拓展 ### 项目文件说明 ```bash .vscode --- VSCode工具的配置文件夹 node-modules --- Vue项目的运行依赖文件夹 public --- 资源文件夹(浏览器图标) src --- 源码文件夹 .gitignore --- git忽略文件 index.html --- 入口HTML文件 package.json --- 信息描述文件 README.md --- 注释文件 vite.config.js --- Vue配置文件 ```

相关推荐
李慕婉学姐4 小时前
【开题答辩过程】以《基于微信小程序垃圾分类图像识别技术实现》为例,不会开题答辩的可以进来看看
spring boot·微信小程序·vue
故事不长丨21 小时前
【Java SpringBoot+Vue 实现视频文件上传与存储】
java·javascript·spring boot·vscode·后端·vue·intellij-idea
咚咚咚小柒1 天前
【前端】Webpack相关(长期更新)
前端·javascript·webpack·前端框架·node.js·vue·scss
老华带你飞2 天前
房屋租赁|房屋出租|房屋租赁系统|基于Springboot的房屋租赁系统设计与实现(源码+数据库+文档)
java·数据库·spring boot·vue·论文·毕设·房屋租赁系统
前端摸鱼匠2 天前
Vue 3 事件修饰符全解析:从 .stop 到 .passive,彻底掌握前端交互的艺术
前端·vue.js·node.js·vue·交互
Crazy Struggle2 天前
.NET 8.0 + Vue 企业级在线培训系统(开源、免费、支持多种主流数据库)
vue·.net 8.0·后台管理系统
韩立学长3 天前
【开题答辩实录分享】以《植物病虫害在线答疑小程序的设计与实现》为例进行答辩实录分享
spring boot·小程序·vue
whltaoin4 天前
【JAVA全栈项目】弧图图-智能图床 SpringBoot+Vue3 :[框架开荒:一文全步骤打通前后端项目全流程]
java·spring boot·vue·开源项目·全栈·cos
清灵xmf5 天前
Vue + TSX 中使用 class 报错 解决方法
vue
专注前端30年6 天前
Vue2 中 v-if 与 v-show 深度对比及实战指南
开发语言·前端·vue