当前位置: 首页 > news >正文

Vue 3 学习路线指南

阶段一:基础入门 (1-2周)

1.1 环境准备

# 安装 Node.js (推荐 18+ 版本)
# 安装 Vue CLI 或使用 Vite
npm create vue@latest my-vue-app
cd my-vue-app
npm install
npm run dev

1.2 Vue 3 核心概念

  • 响应式系统ref(), reactive(), computed()
  • 组合式 APIsetup() 函数
  • 模板语法:插值、指令、事件处理
  • 组件基础:组件定义、Props、Emits
<template><div><h1>{{ title }}</h1><button @click="increment">Count: {{ count }}</button></div>
</template><script setup lang="ts">
import { ref, computed } from 'vue'// 响应式数据
const count = ref(0)
const title = ref('Vue 3 App')// 计算属性
const doubleCount = computed(() => count.value * 2)// 方法
const increment = () => {count.value++
}
</script>

1.3 学习资源

  • Vue 3 官方文档
  • Vue 3 教程
  • 在线练习:Vue SFC Playground

阶段二:组件开发 (2-3周)

2.1 组件通信

<!-- 父组件 -->
<template><ChildComponent :message="parentMessage" @update="handleUpdate"/>
</template><script setup lang="ts">
import { ref } from 'vue'
import ChildComponent from './ChildComponent.vue'const parentMessage = ref('Hello from parent')const handleUpdate = (newMessage: string) => {parentMessage.value = newMessage
}
</script><!-- 子组件 -->
<template><div><p>{{ message }}</p><button @click="updateParent">Update Parent</button></div>
</template><script setup lang="ts">
interface Props {message: string
}interface Emits {(e: 'update', value: string): void
}const props = defineProps<Props>()
const emit = defineEmits<Emits>()const updateParent = () => {emit('update', 'Updated from child')
}
</script>

2.2 生命周期钩子

<script setup lang="ts">
import { onMounted, onUnmounted, onUpdated } from 'vue'// 组件挂载后
onMounted(() => {console.log('组件已挂载')
})// 组件更新后
onUpdated(() => {console.log('组件已更新')
})// 组件卸载前
onUnmounted(() => {console.log('组件即将卸载')
})
</script>

2.3 插槽 (Slots)

<!-- 父组件 -->
<template><Card><template #header><h2>卡片标题</h2></template><p>卡片内容</p><template #footer><button>确定</button></template></Card>
</template><!-- 子组件 Card.vue -->
<template><div class="card"><header><slot name="header"></slot></header><main><slot></slot></main><footer><slot name="footer"></slot></footer></div>
</template>

阶段三:状态管理 (1-2周)

3.1 Pinia 状态管理

// stores/counter.ts
import { defineStore } from 'pinia'export const useCounterStore = defineStore('counter', () => {const count = ref(0)const doubleCount = computed(() => count.value * 2)const increment = () => count.value++const decrement = () => count.value--return { count, doubleCount, increment, decrement }
})

3.2 在组件中使用

<template><div><p>Count: {{ counter.count }}</p><p>Double: {{ counter.doubleCount }}</p><button @click="counter.increment">+1</button></div>
</template><script setup lang="ts">
import { useCounterStore } from '@/stores/counter'const counter = useCounterStore()
</script>

阶段四:路由管理 (1周)

4.1 Vue Router 4

// router/index.ts
import { createRouter, createWebHistory } from 'vue-router'const

文章转载自:

http://vJID3CZk.nhpmn.cn
http://o1TOU2N3.nhpmn.cn
http://yDnebIWK.nhpmn.cn
http://om7PrFV2.nhpmn.cn
http://6cV6ZwRf.nhpmn.cn
http://f9qa2p7s.nhpmn.cn
http://nUsCaOP1.nhpmn.cn
http://0VsYYGtR.nhpmn.cn
http://XUgl0WCQ.nhpmn.cn
http://yKV8ZYBh.nhpmn.cn
http://RWKBoUhe.nhpmn.cn
http://Qq0EuM78.nhpmn.cn
http://L0IiPV2d.nhpmn.cn
http://EdhTtjeE.nhpmn.cn
http://KfYLLyz5.nhpmn.cn
http://duUUq7Zl.nhpmn.cn
http://KkxODUEQ.nhpmn.cn
http://71LiyVYN.nhpmn.cn
http://M7t7M9xI.nhpmn.cn
http://hrFvBlqy.nhpmn.cn
http://U4JK0jO8.nhpmn.cn
http://SDj7rgik.nhpmn.cn
http://c0ui3U48.nhpmn.cn
http://yF8bYnKx.nhpmn.cn
http://ZKRxiMJ8.nhpmn.cn
http://t2xuiLTz.nhpmn.cn
http://9KihnXUm.nhpmn.cn
http://rhM6zW9N.nhpmn.cn
http://bnkoBUrW.nhpmn.cn
http://7bm3vNBm.nhpmn.cn
http://www.dtcms.com/a/366929.html

相关文章:

  • C语言基础:内存管理
  • 大模型应用开发框架 LangChain
  • Deeplizard深度学习课程(六)—— 结合Tensorboard进行结果分析
  • 小程序:12亿用户的入口,企业数字化的先锋军
  • 【C++题解】关联容器
  • 15,FreeRTOS计数型信号量操作
  • PMP新考纲练习题10道【附答案解析】
  • 开源技术助力企业腾飞,九识智能迈入‘数据驱动’新纪元
  • Docker(①安装)
  • [Windows] PDF工具箱 PDF24 Creator 11.28.0
  • 阿里云轻量应用服务器部署-WooCommerce
  • Java全栈开发面试实战:从基础到高并发的深度解析
  • 并非银弹,而是利器:对软件开发工具的深度探讨与理性思考
  • 使用 Sentry 为 PHP 和 Web 移动小程序提供多平台错误监控
  • 文心iRAG - 百度推出的检索增强的文生图技术,支持生成超真实图片
  • node的模块查找策略
  • HarmonyOS应用开发之界面列表不刷新问题Bug排查记:从现象到解决完整记录
  • 如何架设游戏服务器
  • 如何配置安全的 SFTP 服务器?
  • 【连载 1/9】大模型基础入门学习60页大模型应用:(一)绪论【附全文阅读】
  • Vue基础知识-脚手架开发-初始化目录解析
  • Java面试-HashMap原理
  • 开关电源——只需这三个阶段,从电源小白到维修大神
  • Pydantic模型验证测试:你的API数据真的安全吗?
  • Linux高手才知道的C++高性能I/O秘诀:Vector I/O与DMA深度解析
  • DRMOS电源
  • 经典资金安全案例分享:支付系统开发的血泪教训
  • 手机秒变全栈IDE:Claude Code UI的深度体验
  • Go 自建库的使用教程与测试
  • 生活在数字世界:一份人人都能看懂的网络安全生存指南