您的位置:首页 > 健康 > 美食 > 小程序模板素材_松原新闻头条_百度官网优化_全网营销平台有哪些

小程序模板素材_松原新闻头条_百度官网优化_全网营销平台有哪些

2025/3/12 19:09:49 来源:https://blog.csdn.net/weixin_44599931/article/details/146007561  浏览:    关键词:小程序模板素材_松原新闻头条_百度官网优化_全网营销平台有哪些
小程序模板素材_松原新闻头条_百度官网优化_全网营销平台有哪些

创建项目

// 安装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>

.

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com