VUE_使用Vite构建vue项目

创建项目

// 安装vite
npm install vite

// 创建名为vite-app的项目
npm create vite vite-app --template vue

// 到项目目录
cd vite-app

// 安装依赖
npm install

// 运行项目
npm run dev

// 打包
npm run build

// 打包预览
npm run serve

增加路由

// 安装路由
npm add vue-router@4

router/index.js

import { createWebHashHistory, createRouter } from 'vue-router'

const routes = [
	{
		path: '/',
		component: () => import("../pages/index.vue")
	},
	{
		path: '/HelloWorld',
		component: () => import("../pages/HelloWorld.vue")
	}
]

const router = createRouter({
	history: createWebHashHistory(),
	routes,
})

export default router

main.js

import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import router from './router/index.js'

createApp(App).use(router).mount('#app')

App.vue

<template>
	<router-link to="/">index</router-link> |
	<router-link to="/HelloWorld">HelloWorld</router-link> 
    <router-view></router-view>
</template>

index.vue

<template>
	<div>
		这是首页
	</div>
</template>

<script setup>
	import { ref, onMounted, onUnmounted } from 'vue'

	const num = ref(0)
	console.log(num.value)

	onMounted(() => {})
	onUnmounted(() => {})
</script>

<style lang='scss' scoped>
	
</style>

.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值