https://vitejs.cn/guide/#%E6%90%AD%E5%BB%BA%E7%AC%AC%E4%B8%80%E4%B8%AA-vite-%E9%A1%B9%E7%9B%AE
第一步
npm init @vitejs/app
第二部
npm install
第三步 启动
npm run dev
这时会发现项目中有多处报红线,需要设置

解决方法:

1,首先检查html片段没有语法错误的话,就是一个检查语法格式的插件"vetur"引起的。

2,解决方法是:vscode -> 首选项 -> 设置 -> 搜索 (vetur),将vetur.validation.template 设置为 false 就可以解决问题了。

以解决问题了。

不要使用Vetur 插件,而是使用Vue Language Features(Volar) 所有的报错都消失了

//解决vite   use `--host` to expose
 server:{
    host:'0.0.0.0',//解决vite   use `--host` to expose
    port:8080,
    open:true
  }

运行自动打开需要安装

 //vite 配置别名 npm install @types/node --save-dev
  resolve:{
    alias:[
      {
         find:'@',
         replacement:resolve(__dirname,'src')
      }
    ]
  }
 
整体结构
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path' // https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()],
server:{
host:'0.0.0.0',//解决vite use `--host` to expose
port:8080,
open:true
},
//vite 配置别名 npm install @types/node --save-dev
resolve:{
alias:[
{
find:'@',
replacement:resolve(__dirname,'src')
}
]
}
})

配置路由

npm install vue-router@4

然后在 src 文件下创建 router 文件夹
再在router 文件夹下创建 index.ts
内容如下
import {createRouter,createWebHistory,RouteRecordRaw} from 'vue-router'
import Layout from '@/components/HelloWorld.vue'
const routes:Array<RouteRecordRaw>=[
{
path:'/',
name:'home',
component:Layout
}
]
//创建
export default createRouter({
history:createWebHistory(),
routes
})

再到main.ts 中使用路由

import router  from './router'
createApp(App).use(router).mount('#app')
 
 
然後在:App.vue 中添加
<script setup lang="ts">
// This starter template is using Vue 3 <script setup> SFCs
// Check out https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup
import HelloWorld from './components/HelloWorld.vue'
</script> <template>
<router-view/>
</template> <style> </style>
 
 
安装  Vuex

npm install vuex@next --save
在src 目录下建立store 然后在下面再新建index.ts

import { InjectionKey } from 'vue'
import { createStore, useStore as baseUseStore, Store } from 'vuex' export interface State {
count: number
} export const key: InjectionKey<Store<State>> = Symbol() export const store = createStore<State>({
state: {
count: 0
},
mutations:{
setCount(state:State,count:number){
state.count=count;
}
},
getters:{
getCount(state:State){
return state.count;
}
}
}) // 定义自己的 `useStore` 组合式函数
export function useStore () {
return baseUseStore(key)
}


安装 eslint
npm install --save-dev eslint eslint-plugin-vue
在根目录下创建文件 .eslintrc.js

module.exports = {
    root:true,
    parserOptions:{
        sourceType:'module'
    },
    parser:'vue-eslint-parser',
    extends: ['plugin:vue/vue3-essential','plugin:vue/vue3-strongly-recommended','plugin:vue/vue3-recommended'],
    env:{
        browser:true,
        node:true,
        es6:true
    },
    rules: {
        'no-console':'off',
        'comma-dangle':[2,'never']//禁止使用拖尾逗号
    }
}

安装 css 的预处理 sass

npm install -D sass sass-loader

设置Index.html 的页面样式

<style>
html,body,#app{
margin: 0;
padding: 0;
border: 0;
border-collapse: collapse;
border-spacing: 0;
list-style: none;
height: 100%;
}
</style>

tsconfig.json

{
"compilerOptions": {
"target": "esnext",
"useDefineForClassFields": true,
"module": "esnext",
"moduleResolution": "node",
"strict": true,
"jsx": "preserve",
"sourceMap": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"lib": ["esnext", "dom"],
"skipLibCheck": true,//解决打包报 'vue-tsc --noEmit && vite build'的错,忽略所有的声明文件(*.d.ts)的类型检查
"baseUrl": ".", // 用于设置解析非相对模块名称的基本目录,相对模块不会受到baseUrl的影响
"paths": { // 用于设置模块名到基于baseUrl的路径映射
"@/*":["src/*"]
},
"types": ["element-plus/global"]
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
"references": [{ "path": "./tsconfig.node.json" }],
"exclude": ["node_modules"]//ts 排除的文件
}

 
首先检查html片段没有语法错误的话,就是一个检查语法格式的插件"vetur"引起的。
 

VisualStudioCode 创建Vue 3.0 项目的更多相关文章

  1. 创建 Angular 8.0 项目

    创建 Angular 8.0 项目,首先确保已经安装了 nodejs,如果没有安装,请看这篇文章安装:node.js 安装 1.新建一个空文件夹 angularproject,作为工作区 2.安装 A ...

  2. 用Eclipse Maven 创建 Web 3.0 项目问题 正确的处理步骤

    在Eclipse 安装好Maven插件后,创建Maven webapp项目,在工程 properties -> project facets 界面中将 Dynamic Web Module 修改 ...

  3. Vue cli2.0 项目中使用Monaco Editor编辑器

    monaco-editor 是微软出的一条开源web在线编辑器支持多种语言,代码高亮,代码提示等功能,与Visual Studio Code 功能几乎相同. 在项目中可能会用带代码编辑功能,或者展示代 ...

  4. vue 3.0 项目搭建移动端 (七) 安装Vant

    # 通过 npm 安装 npm i vant -S 安装完配置 babel.config.js module.exports = { presets: ['@vue/app'], plugins: [ ...

  5. Vue 2.0 项目在IE下显示空白

    新写的项目在 IE浏览器显示空白 解释一: Babel默认只转换新的JavaScript句法(syntax),而不转换新的API,比如Iterator.Generator.Set.Maps.Proxy ...

  6. vue 3.0 项目搭建移动端 (六) 命名路由同级控制

    const Tabbar = () => import('@/components/Tabbar'); export default [ { path: '/', name: 'home', c ...

  7. vue2.0与vue3.0项目创建

    脚手架安装与卸载 安装 npm install -g vue-cli //or npm install -g @vue/cli 卸载 npm uninstall -g vue-cli //or npm ...

  8. vue 3.0 体验,vue 3.0新特性

    前言 昨天不是尤雨溪 不是刚在B站 直播玩了,分享了vue-next v3.0.0-beta.1 版本 哈哈, 不要太刺激哦 6大亮点 Performance:性能更比Vue 2.0强. Tree s ...

  9. VisualStudioCode创建的asp.net core项目部署到linux,使用nginx代理

    1.准备工作: a:使用VisualStudioCode创建asp.net core项目,并使用命令“dotnet publish”发布(可以参考前面两篇文章). 如:dotnet publish - ...

  10. Vue 3.0 升级指南

    本文由葡萄城技术团队原创并首发 转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 2020年9月18日Vue 3.0正式发布,距离2016年10月1日Vue ...

随机推荐

  1. wrk

    github.com/wg/wrk 是一个现代的 HTTP 基准测试工具.

  2. KGDB调试Linux内核与模块

    前言 内核 5.10 版本 openEuler 使用 yum install 下载了源码,并且通过两个 VMware 虚拟机进行调试 ubuntu 直接使用 git 拉取了https://kernel ...

  3. P5490 【模板】扫描线 & 矩形面积并 做题笔记

    扫描线是一种很常用的 trick,用来计算矩形并周长.并面积.核心思路是使用标记永久化 + 线段树,直接引用朴素的做法,即从某一维度开始扫描并将经过的面积加和. 错误 upd 函数中的汇总不正确,要想 ...

  4. windows10 激活教程

    1.环境 适用对象:VL版本的windows OEM版本请使用文末工具激活 1.1查询自己电脑版本 [win+R]->输入[slmgr /dlv]->查看[产品密钥通道] slmgr /d ...

  5. 墨刀上线高级交互功能,能否超越Axure?

    引言 近期,国内主流原型设计工具墨刀推出了"变量.条件判断.函数"等功能,立刻在交互设计师与资深产品经理群体中引起热议.作为国产轻量级原型设计工具的龙头代表,墨刀早已俘获了中小团队 ...

  6. CTF实验吧加了料的报错注入

    实验吧地址 http://ctf5.shiyanbar.com/web/baocuo/index.php F12审查元素发现源码中的提示是这样一整句的查询 基本确定此题为一个SQL注入 /# = un ...

  7. JavaScript环境搭建与调试

    JavaScript的环境搭建非常简单,一个Chrome浏览器(实际上任何浏览器都自带有JavaScript解释器,Chrome对调试更友好,下载链接:http://www.51xiazai.cn/s ...

  8. C#快速排序算法实现及循环条件细节思考

    C#快速排序算法实现及循环条件细节思考 快速排序是一种分治思想的递归排序算法,其基本思想为: 在每一步中,挑选一个主元(pivot)出来,比如第一个元素 然后遍历除主元外的剩下的元素,把所有小于主元的 ...

  9. .NET外挂系列:3. 了解 harmony 中灵活的纯手工注入方式

    一:背景 1. 讲故事 上一篇我们讲到了 注解特性,harmony 在内部提供了 20个 HarmonyPatch 重载方法尽可能的让大家满足业务开发,那时候我也说了,特性虽然简单粗暴,但只能解决 9 ...

  10. Special Binary String——LeetCode进阶路

    原题链接https://leetcode.com/problems/special-binary-string/ 题目描述 Special binary strings are binary stri ...