Vue3 + TypeScript + Vite + Echarts + DataV

Vue3 + TypeScript + Vite + Echarts + DataV

datav

官网:

datav

datav-vue3

1、创建工程

npm create vite@latest
cd datav-app
npm install
npm run dev

2、安装项目依赖模块

npm install @types/node --save-dev

npm install vue-router@4

npm install animate.css --save
npm install gsap --save

npm install fetch --save
npm install axios --save

npm install pinia

npm install less less-loader -D
npm install sass sass-loader --save-dev
npm install scss scss-loader --save-dev

npm install element-plus --save
npm install -D unplugin-vue-components unplugin-auto-import

npm install echarts echarts-wordcloud --save
npm install @kjgl77/datav-vue3

3、配置项目

vite.config.ts

import {
   
   defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import {
   
   resolve} from "node:path";

const base = 'http://140.143.190.15:8080'
// https://vitejs.dev/config/
export default defineConfig({
   
   
  plugins: [vue()],
  server: {
   
   
    host: '0.0.0.0',
    port: 5173,
    open: true,
    proxy: {
   
   
      '/api': {
   
   
        target: base,  //目标代理接口地址
        secure: false,
        changeOrigin: true,  //开启代理,在本地创建一个虚拟服务器
        PathRewrite: {
   
   
          '^/api': '/api'
        }
      }
    }
  },
})

3.1 配置路径别名

vite.config.ts

import {
    
    resolve} from "node:path";

resolve: {
    
    
    alias: {
    
    
      '@': resolve(__dirname, 'src')
    },
    // 引入文件的时候,可以忽略掉以下文件后缀
    // extensions: ['.js', '.mjs', '.vue', '.json', '.less', '.css']
  },
import {
   
   defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import {
   
   resolve} from "node:path";

const base = 'http://140.143.190.15:8080'
// https://vitejs.dev/config/
export default defineConfig({
   
   
  plugins: [vue()],
  server: {
   
   
    host: '0.0.0.0',
    port: 5173,
    open: true,
    proxy: {
   
   
      '/api': {
   
   
        target: base,  //目标代理接口地址
        secure: false,
        changeOrigin: true,  //开启代理,在本地创建一个虚拟服务器
        PathRewrite: {
   
   
          '^/api': '/api'
        }
      }
    }
  },
  resolve: {
   
   
    alias: {
   
   
      '@': resolve(__dirname, 'src')
    }
  },
})

ts.config.node.json

/* 路径别名 */
"types": ["node"],
"baseUrl": ".",
"paths": {
    
    
  "@/*": ["src/*"]
}
{
   
   
  "compilerOptions": {
   
   
    "target": "ES2022",
    "lib": ["ES2023"],
    "module": "ESNext",
    "skipLibCheck": true,

    /* Bundler mode */
    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "isolatedModules": true,
    "moduleDetection": "force",
    "noEmit": true,

    /* Linting */
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noFallthroughCasesInSwitch": true,


    /* 路径别名 */
    "types": ["node"],
    "baseUrl": ".",
    "paths": {
   
   
      "@/*": ["src/*"]
    }
  },
  "include": ["vite.config.ts"]
}

3.2 引入路由

3.2.1 创建路由出口视图并在 app.vue 组件中引入 路由出口视图

DataV.vue

<script setup lang="ts">

</script>

<template>
  <router-view/>
</template>

<style scoped>

</style>

app.vue

<script setup lang="ts">
import HelloEcharts from "@/components/DataV.vue";
</script>

<template>
  <data-v/>
</template>

<style scoped>
</style>

3.2.2 创建路由文件

router.ts

// 1. 定义路由组件.
// 也可以从其他文件导入
import {
   
   createMemoryHistory, createRouter, RouteRecordRaw} from 'vue-router'
// 2. 定义一些路由
const routes: Array<RouteRecordRaw> = [
]
// 3. 创建路由实例并传递 `routes` 配置
// 你可以在这里输入更多的配置,但我们在这里
// 暂时保持简单
const router = createRouter({
   
   
  // 4. 内部提供了 history 模式的实现。
  // memory 模式。createMemoryHistory
  // hash 模式。createWebHashHistory
  // html5 模式。createWebHistory
  history: createMemoryHistory(),
  routes,
})

export default
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

李昊哲小课

桃李不言下自成蹊

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值