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
  • 浏览器打开这个网址,说明创建成功

开发环境

推荐的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配置文件
相关推荐
山海云端有限公司11 小时前
随机诗词API实战:Vue项目接入完整示例与5个常见坑
vue·实战·前端开发·跨域·api调用·随机诗词api
暗冰ཏོ19 小时前
Spring Boot + Vue3 订单支付模块技术实现:支付单、回调验签、幂等处理与余额扣减
前端·spring boot·后端·vue·微信支付·支付宝支付
万亿少女的梦1682 天前
基于Python的高考志愿填报辅助系统设计与实现
java·spring boot·python·mysql·vue
万亿少女的梦1682 天前
基于SpringBoot与Vue的历史博物馆展品展示与游客管理系统设计
spring boot·mysql·vue·系统设计·博物馆管理系统
衍生星球2 天前
SpringBoot3 + Vue3 + 微信小程序如何学习,以及学哪些技术,组件
sql·微信小程序·uni-app·vue·springboot
志尊宝3 天前
Vue3 环境搭建 + 第一个 HelloVue 项目(零基础入门)
vue.js·node.js·vue·css3
万亿少女的梦1683 天前
基于Spring Boot与Vue的繁星技术论坛系统设计与实现
java·spring boot·mysql·vue·系统设计
随心(cracker)4 天前
BeaverX Admin:一套真正能跑起来的开源管理后台
vue·.net·管理后台
万亿少女的梦1684 天前
基于SpringBoot的考研学习交流系统设计与开发
spring boot·mysql·vue·系统设计·论坛系统
格子软件4 天前
2026年GEO贴牌代理:分布式多级分账状态机源码深度解构
java·vue.js·分布式·vue·geo