当前位置: 首页 > 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混合一起 。

相关文章:

  • Image Fusion via Vision-Language Model【文献阅读】
  • React Switch用法及手写Switch实现
  • 初学者如何学习python
  • leetcode 热题 100_三数之和
  • LeetCode——二叉树(Java)
  • 【Vue3】PostCss 适配
  • GO基本类型一些记录
  • Spring八股 常见面试题
  • 爆红提醒:ESLint: Parsing error: Unexpected token. Did you mean `{‘>‘}` or `gt;`?
  • Java如何添加批量添加水印
  • 【vue3】命令式组件封装,message封装示例;(函数式组件?)
  • 监听者的力量:探索观察者模式和spring使用
  • [NOIP2007 普及组] 纪念品分组--贪心算法
  • 论文里点击如图?-?如何跳转到图片的题注
  • 探秘SpringBoot启动流程:原理解析与自定义扩展
  • 分享的文章《人生如棋》
  • angular2开源库收集
  • C++入门教程(10):for 语句
  • Druid 在有赞的实践
  • Laravel Telescope:优雅的应用调试工具
  • Linux链接文件
  • nginx 负载服务器优化
  • php的插入排序,通过双层for循环
  • Spark学习笔记之相关记录
  • windows-nginx-https-本地配置
  • 从0到1:PostCSS 插件开发最佳实践
  • 从零开始的webpack生活-0x009:FilesLoader装载文件
  • 湖南卫视:中国白领因网络偷菜成当代最寂寞的人?
  • 机器人定位导航技术 激光SLAM与视觉SLAM谁更胜一筹?
  • 记一次删除Git记录中的大文件的过程
  • 两列自适应布局方案整理
  • 使用agvtool更改app version/build
  • 使用Envoy 作Sidecar Proxy的微服务模式-4.Prometheus的指标收集
  • 使用前端开发工具包WijmoJS - 创建自定义DropDownTree控件(包含源代码)
  • 腾讯优测优分享 | Android碎片化问题小结——关于闪光灯的那些事儿
  • 网络应用优化——时延与带宽
  • FaaS 的简单实践
  • k8s使用glusterfs实现动态持久化存储
  • Spring第一个helloWorld
  • ​渐进式Web应用PWA的未来
  • ​人工智能之父图灵诞辰纪念日,一起来看最受读者欢迎的AI技术好书
  • #HarmonyOS:Web组件的使用
  • #LLM入门|Prompt#3.3_存储_Memory
  • #调用传感器数据_Flink使用函数之监控传感器温度上升提醒
  • #我与虚拟机的故事#连载20:周志明虚拟机第 3 版:到底值不值得买?
  • (day 2)JavaScript学习笔记(基础之变量、常量和注释)
  • (env: Windows,mp,1.06.2308310; lib: 3.2.4) uniapp微信小程序
  • (javascript)再说document.body.scrollTop的使用问题
  • (M)unity2D敌人的创建、人物属性设置,遇敌掉血
  • (poj1.3.2)1791(构造法模拟)
  • (附源码)spring boot公选课在线选课系统 毕业设计 142011
  • (黑马C++)L06 重载与继承
  • (转)视频码率,帧率和分辨率的联系与区别
  • (转)总结使用Unity 3D优化游戏运行性能的经验
  • .bashrc在哪里,alias妙用