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

vue3 + vite 项目可以使用纯Js开发吗?

答案:可以

创建项目:

按照链接参考或者按官方:

webstorm 创建vue3 vite 项目-CSDN博客

 项目目录

tsconfig.json 配置允许js

allowJs指定是否编译js文件,在任意文件当中,如果我们模块使用js写的,那么我们需要

  将allowJs设置为true,默认为false,主要是在引入一个额外js之后防止路径错误才使用


{"compilerOptions": {//是否对js进行编译"allowJs": true}
}

打开项目之后创建一个新vue视图

login.vue

<template><div class="about"><h1>This is an Login page</h1><br/><el-divider/><h4>{{ msg }}</h4><el-button @click="handleClick">这个是el按钮</el-button></div>
</template>
<script setup>
const handleClick = () => {msg.value = msg.value + ',hello'alert('点了一下了55555~~~')
}
const msg = ref('hello')</script><style>
@media (min-width: 1024px) {.about {min-height: 100vh;display: flex;align-items: center;flex-direction: column;}
}
</style>

/router/index.ts 添加到路由

import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'const router = createRouter({history: createWebHistory(import.meta.env.BASE_URL),routes: [{path: '/',name: 'home',component: HomeView},{path: '/about',name: 'about',// route level code-splitting// this generates a separate chunk (About.[hash].js) for this route// which is lazy-loaded when the route is visited.component: () => import('../views/AboutView.vue')},{path: '/login',name: 'login',component: () => import('../views/loginView.vue')}]
})export default router

App.vue里遍历路由展示所有的页面,包括上面的login.vue

<template><header><img alt="Vue logo" class="logo" src="@/assets/logo.svg" width="125" height="125" /><div class="wrapper"><HelloWorld msg="You did it!" /><nav><RouterLink v-for="item of routes" :to="item" :key="item.name">{{ item.name }}</RouterLink></nav></div></header><!--RouterLink的跳转的页面内容将在RouterView显示--><RouterView />
</template>
<script setup lang="ts">
import { RouterLink, RouterView } from 'vue-router'
import HelloWorld from './components/HelloWorld.vue'
import router from '@/router'const routes = router.options.routes
// console.log(router.options.routes)
</script><style scoped>
header {line-height: 1.5;max-height: 100vh;background-color: #bfc;
}.logo {/*display: block;*/display: none;margin: 0 auto 2rem 2rem;
}nav {width: 100%;font-size: 12px;text-align: center;margin-top: 2rem;
}nav a.router-link-exact-active {color: var(--color-text);
}nav a.router-link-exact-active:hover {background-color: transparent;
}nav a {display: inline-block;padding: 0 1rem;border-left: 1px solid var(--color-border);
}nav a:first-of-type {border: 0;
}@media (min-width: 1024px) {header {display: flex;place-items: center;padding-right: calc(var(--section-gap) / 2);}.logo {display: block;margin: 0 2rem 0 2rem;}header .wrapper {display: flex;place-items: flex-start;flex-wrap: wrap;}nav {text-align: left;margin-left: -1rem;font-size: 1rem;padding: 1rem 0;margin-top: 1rem;}
}
</style>
运行效果:

总结

vue3+vite + Typescript的项目,按官方创建的项目,也可以用纯JS开发新页面与新功能,只不过是跟项目TS混合一起 。

http://www.lryc.cn/news/312942.html

相关文章:

  • Java EE之线程安全问题
  • 掌握Nodejs高级图片压缩技巧提升web优化
  • C++初阶 类(上)
  • 图片速览 BitNet: 1-bit LLM
  • 金融基础——拨备前利润和拨备后利润介绍
  • 网络编程作业day7
  • 【Vision Pro杀手级应用】3D音乐会/演唱会,非VR视频播放的形式,而是实实在在的明星“全息”形象,在你的面前表演
  • 变频器学习
  • Linux Ubuntu系统安装MySQL并实现公网连接本地数据库【内网穿透】
  • 0048__Unix传奇
  • 蓝桥杯-排序
  • 计算机设计大赛 深度学习的视频多目标跟踪实现
  • 高性能JSON框架之FastJson的简单使用
  • ★判断素数的几种方法(由易到难,由慢到快)
  • vue svelte solid 虚拟滚动性能对比
  • IDEA中新增文件,弹出框提示是否添加到Git点错了,怎么重新设置?
  • LV15 day5 字符设备驱动读写操作实现
  • Uninty 鼠标点击(摄像机发出射线-检测位置)
  • 描述下Vue自定义指令
  • 2024.3.7
  • this.$watch 侦听器 和 停止侦听器
  • P1030 [NOIP2001 普及组] 求先序排列题解
  • 【分布式】NCCL Split Tree kernel内实现情况 - 06
  • C语言深入学习 --- 4.自定义类型(结构体+枚举+联合)
  • AI自然语言中默认上下文长度4K 几K是什么意思?
  • vSphere 8考试认证题库 2024最新(VCP 8.0版本)
  • 系统学习Python——装饰器:“私有“和“公有“属性案例-[装饰器参数、状态保持和外层作用域]
  • 星辰天合参与编制 国内首个可兼顾 AI 大模型训练的高性能计算存储标准正式发布
  • 算法训练day38动态规划基础Leetcode509斐波纳切数70爬楼梯746使用最小花费爬楼梯
  • Leetcode 206. 反转链表