svelte+vite+ts+melt-ui从0到1完整框架搭建

框架太“重”了:通常一个小型项目只由少数几个简单页面构成,如果使用 Vue 或者 React 这些框架来研发的话,有点“大材小用”了。构建的产物中包含了不少框架运行时代码(虚拟 DOM、响应式、状态管理等),这些代码对于小型项目而言是冗余的,它们影响了包体大小,进而影响页面的启动速度和执行性能。
打包太慢了:以 Vue CLI 为例,它的底层基于 Webpack,虽然 Webpack 具备更强大的功能和灵活性,但相比于 Vite、Esbuild 这些以速度为标杆的构建工具来说,它的速度确实慢了一些,影响了研发效率。

文章目录

    • 一、 创建基本项目
      • 1.1 全局安装 Vite
      • 1.2 创建 Svelte 项目
    • 二、目录结构
    • 三、svelte路由配置
      • 3.1 npm安装
      • 3.2 定义router
        • 3.2.1 动态导入组件
        • 3.2.2 在页面之间导航
      • 3.3 使用路由
    • 四、svelte CSS预处理器
      • 4.1 less的使用
        • 4.1.1 npm安装
      • 4.2 Tailwind CSS的使用
    • 五、svelte环境变量配置
      • 5.1 环境变量命名规则
      • 5.2 .env文件的使用
      • 5.3 在代码中使用环境变量
      • 5.4 配置运行与打包环境
    • 六、svelte国际化
      • 6.1 安装 `svelte-i18n`
      • 6.2 初始化 `svelte-i18n`
      • 6.3 创建语言文件
      • 6.4 在 Svelte 组件中使用 `svelte-i18n`
      • 6.5 切换语言
      • 6.6 在 `App.svelte` 中引入 `i18n.js`
      • 6.7 运行项目
      • 6.8 构建项目
      • 6.9 预览项目
      • 6.10 检查项目
    • 七、svelte接口请求
      • 7.1 安装 `axios`
      • 7.2 创建 `axios` 实例
      • 7.3 在 Svelte 组件中使用 `axios`
      • 7.4 处理请求和响应拦截器
      • 7.5 在 `App.svelte` 中使用 `axios`
      • 7.6 处理错误
    • 八、svelte组件库
    • 九、svelte阿里图标库
      • 9.1 获取阿里图标
      • 9.2 将图标文件放入项目
      • 9.3 引入图标文件
      • 9.4 使用图标
      • 9.5 动态切换图标
      • 9.6 使用 Symbol 方式(可选)
      • 9.7 样式调整(可选)
      • 9.8 示例代码
    • 十、svelte轮播图
    • 十一、store数据共享
      • 1. 创建 `store` 模块
      • 2. 创建全局 `store`
      • 3. 在组件中使用 `store`
      • 4. 封装 `store` 的优势
      • 5. 示例:`about.svelte` 中使用 `store`
    • 十二、扩展内容
    • 十三、框架git地址

一、 创建基本项目

1.1 全局安装 Vite

通过 npm 全局安装 Vite

npm install vite 

1.2 创建 Svelte 项目

Vite 原生支持直接通过脚手架创建 Svelte 项目,执行以下命令

npm create vite@latest

输入命令后选择如下

✔ Project name: vite-svelte? Select a framework: › - Use arrow-keys. Return to submit.VanillaVueReactPreactLit
❯   SvelteSolidQwikOthers? Select a variant: › - Use arrow-keys. Return to submit.TypeScript
❯   JavaScriptSvelteKit

基本项目创建完成

二、目录结构

根据上一步创建项目,项目的基本结构栓是完成了,但这样还是不够的,接下来介绍一下完整的项目目录
在这里插入图片描述

三、svelte路由配置

3.1 npm安装

项目中安装svelte-spa-router

npm install svelte-spa-router

3.2 定义router

  • 每条路由都是一个普通的Svelte组件,包含标记、脚本、绑定等。任何Svelte组件都可以是路由。
  • 路由定义只是一个JavaScript字典(对象),其中键是一个带有路径(包括参数等)的字符串,值是路由对象。
import Home from './routes/Home.svelte'
import Author from './routes/Author.svelte'
import Book from './routes/Book.svelte'
import NotFound from './routes/NotFound.svelte'const routes = {// Exact path'/': Home,// Using named parameters, with last being optional'/author/:first/:last?': Author,// Wildcard parameter'/book/*': Book,// Catch-all// This is optional, but if present it must be the last'*': NotFound,
}
3.2.1 动态导入组件

使用动态导入的优点是,如果您的打包器支持,您可以启用代码拆分并减小发送给用户的捆绑包的大小。这已经用包括Rollup和Webpack在内的捆绑器进行了测试

  1. 要使用动态导入的组件,您需要利用包装方法(根据路线包装文档,该方法可用于各种操作)。首先,导入wrap方法:
import {wrap} from 'svelte-spa-router/wrap'
  1. 然后,在路由定义中,使用wrap方法包装路由,将一个函数传递给asyncComponent属性,该函数将动态导入的组件返回给asyncComponent:
wrap({asyncComponent: () => import('./Foo.svelte')
})

案例:

// Import the wrap method
import {wrap} from 'svelte-spa-router/wrap'// Note that Author and Book are not imported here anymore, so they can be imported at runtime
import Home from './routes/Home.svelte'
import NotFound from './routes/NotFound.svelte'const routes = {'/': Home,// Wrapping the Author component'/author/:first/:last?': wrap({asyncComponent: () => import('./routes/Author.svelte')}),// Wrapping the Book component'/book/*': wrap({asyncComponent: () => import('./routes/Book.svelte')}),// Catch-all route last'*': NotFound,
}
3.2.2 在页面之间导航
  1. 锚点导航
<a href="#/book/123">Thus Spoke Zarathustra</a>
  1. use:link导航(可以使用use:link操作,而不必在每个链接前键入#)
<script>
import {link} from 'svelte-spa-router'
</script>
<a href="/book/321" use:link>The Little Prince</a>

3.3 使用路由

在app.svelte中全局调用

import Router from 'svelte-spa-router'

然后,通过将组件放置在标记中,将路由器显示在您想要的任何位置

<body><Router {routes}/>
</body>

四、svelte CSS预处理器

4.1 less的使用

4.1.1 npm安装

安装less与svelte-preprocess-less依赖

npm install --save-dev svelte-preprocess-less less

在vite.config.js进行配置

import { less } from 'svelte-preprocess-less'
export default defineConfig({plugins: [svelte({preprocess: {style: less(),},})],
})

4.2 Tailwind CSS的使用

通过npx安装直接配置完 tailwindcss

npx sv add tailwindcss

五、svelte环境变量配置

‌Vite中使用环境变量主要通过.env文件来配置,这些文件根据不同的环境(开发、测试、生产等)有不同的命名规则和使用方式。

5.1 环境变量命名规则

所有环境变量必须以VITE_为前缀

VITE_API_URL=https://api.example.com
VITE_APP_TITLE=My Vite App

5.2 .env文件的使用

1‌. 通用环境变量‌:在项目的根目录下创建.env文件,用于定义所有环境通用的变量。
2‌. 特定环境变量‌:根据不同的环境需求,可以创建以下类型的.env文件:
.env.devt:仅在开发环境中使用。
.env.pro:仅在生产环境中使用。
.env.local:通用的本地配置文件,通常不提交到版本控制系统中。
.env.development.local:开发环境的本地配置文件。
.env.production.local:生产环境的本地配置文件‌

5.3 在代码中使用环境变量

console.log(import.meta.env.VITE_API_URL);

5.4 配置运行与打包环境

  "scripts": {"dev": "vite --mode dev",//运行dev环境"dev-pro": "vite --mode pro",//运行pro环境"build": "vite build","preview": "vite preview","check": "svelte-check --tsconfig ./tsconfig.app.json && tsc -p tsconfig.node.json"},

六、svelte国际化

svelte-i18n 是一个用于 Svelte 应用的国际化(i18n)库,它可以帮助你轻松地管理和切换应用中的多语言内容。以下是如何在 Svelte 项目中使用 svelte-i18n 的基本步骤:

6.1 安装 svelte-i18n

首先,确保你已经安装了 svelte-i18n。根据你的 package.json 文件,它已经存在于 dependencies 中。

npm install svelte-i18n

6.2 初始化 svelte-i18n

在你的 Svelte 项目中,通常会在 src 目录下创建一个 i18n.jsi18n.ts 文件来初始化 svelte-i18n

// src/i18n.js
import { init, register, locale } from 'svelte-i18n';// 注册默认语言
register('en', () => import('./locales/en.json'));
register('zh', () => import('./locales/zh.json'));// 初始化并设置默认语言
init({fallbackLocale: 'en',initialLocale: 'en',
});

6.3 创建语言文件

src/locales 目录下创建语言文件,例如 en.jsonzh.json

// src/locales/en.json
{"welcome": "Welcome to Svelte App","greeting": "Hello, {name}!"
}
// src/locales/zh.json
{"welcome": "欢迎使用 Svelte 应用","greeting": "你好, {name}!"
}

6.4 在 Svelte 组件中使用 svelte-i18n

你可以在 Svelte 组件中使用 $t 函数来获取翻译内容。

<script>import { t } from 'svelte-i18n';
</script><h1>{$t('welcome')}</h1>
<p>{$t('greeting', { name: 'John' })}</p>

6.5 切换语言

你可以通过 locale.set 方法来动态切换语言。

<script>import { locale } from 'svelte-i18n';
</script><button on:click={() => locale.set('en')}>English</button>
<button on:click={() => locale.set('zh')}>中文</button>

6.6 在 App.svelte 中引入 i18n.js

  1. 确保在 App.svelte 或你的主入口文件中引入 i18n.js
<script>import './i18n.js';
</script>
  1. 确保加载完i18n后在加载页面
<script>import { locale } from "svelte-i18n";import Router from "@/router/Router.svelte";
</script>
{#if $locale}<Layout><Router /></Layout>
{/if}

6.7 运行项目

使用 npm run dev 运行你的项目,你应该能够看到国际化内容并根据按钮切换语言。

6.8 构建项目

当你准备好发布项目时,使用 npm run build 来构建项目。

npm run build

6.9 预览项目

使用 npm run preview 来预览构建后的项目。

npm run preview

6.10 检查项目

使用 npm run check 来检查 Svelte 和 TypeScript 的类型。

npm run check

通过以上步骤,你应该能够在 Svelte 项目中成功使用 svelte-i18n 来实现国际化功能。

七、svelte接口请求

在 Svelte 项目中使用 axios 进行 HTTP 请求是非常常见的操作。以下是如何在 Svelte 项目中集成和使用 axios 的步骤:

7.1 安装 axios

首先,确保你已经安装了 axios。根据你的 package.json 文件,它已经存在于 dependencies 中。

npm install axios

7.2 创建 axios 实例

为了更好的管理和配置 axios,通常会在 src/utils 目录下创建一个 api.tsapi.js 文件来创建 axios 实例。

// src/utils/api.ts
import axios from 'axios';const api = axios.create({baseURL: 'https://api.example.com', // 你的 API 基础 URLtimeout: 10000, // 请求超时时间headers: {'Content-Type': 'application/json',},
});export default api;

7.3 在 Svelte 组件中使用 axios

你可以在 Svelte 组件中导入并使用 axios 实例来发送 HTTP 请求。

<script lang="ts">import api from '@/utils/api';import { onMount } from 'svelte';let data: any;onMount(async () => {try {const response = await api.get('/endpoint');data = response.data;} catch (error) {console.error('Error fetching data:', error);}});
</script>{#if data}<div><h1>{data.title}</h1><p>{data.description}</p></div>
{/if}

7.4 处理请求和响应拦截器

你可以在 axios 实例中添加请求和响应拦截器,以便在请求发送前或响应到达后进行一些处理。

// src/utils/api.ts
import axios from 'axios';const api = axios.create({baseURL: 'https://api.example.com',timeout: 10000,headers: {'Content-Type': 'application/json',},
});// 请求拦截器
api.interceptors.request.use((config) => {// 在请求发送之前做一些处理,例如添加 tokenconst token = localStorage.getItem('token');if (token) {config.headers.Authorization = `Bearer ${token}`;}return config;},(error) => {return Promise.reject(error);}
);// 响应拦截器
api.interceptors.response.use((response) => {// 对响应数据做一些处理return response;},(error) => {// 对响应错误做一些处理return Promise.reject(error);}
);export default api;

7.5 在 App.svelte 中使用 axios

你可以在 App.svelte 中使用 axios 来获取数据或执行其他 HTTP 操作。

<script lang="ts">import api from '@/utils/api';import { onMount } from 'svelte';let userData: any;onMount(async () => {try {const response = await api.get('/user');userData = response.data;} catch (error) {console.error('Error fetching user data:', error);}});
</script>{#if userData}<div><h1>Welcome, {userData.name}!</h1><p>Email: {userData.email}</p></div>
{/if}

7.6 处理错误

在使用 axios 时,确保你处理了可能的错误,例如网络错误或服务器错误。

<script lang="ts">import api from '@/utils/api';import { onMount } from 'svelte';let userData: any;let errorMessage: string | null = null;onMount(async () => {try {const response = await api.get('/user');userData = response.data;} catch (error) {errorMessage = 'Failed to fetch user data. Please try again later.';console.error('Error fetching user data:', error);}});
</script>{#if userData}<div><h1>Welcome, {userData.name}!</h1><p>Email: {userData.email}</p></div>
{:else if errorMessage}<p style="color: red;">{errorMessage}</p>
{/if}

通过以上步骤,你应该能够在 Svelte 项目中成功使用 axios 来进行 HTTP 请求。

八、svelte组件库

这里用的是melt-ui,访问地址是:https://www.melt-ui.com/docs/introduction
一键配置

npx @melt-ui/cli@latest init

九、svelte阿里图标库

在 Svelte 项目中使用阿里图标(如 iconfont)可以通过以下步骤实现:


9.1 获取阿里图标

  1. 访问 iconfont 并登录。
  2. 创建一个项目,将需要的图标添加到项目中。
  3. 选择 Font classSymbol 方式生成代码。
  4. 点击 下载至本地,解压后得到图标文件。

9.2 将图标文件放入项目

将下载的图标文件(如 iconfont.css 和字体文件)放入项目的 publicsrc/assets 目录中。

例如:

public/iconfont/iconfont.cssiconfont.ttficonfont.wofficonfont.woff2

9.3 引入图标文件

App.sveltemain.ts 中引入 iconfont.css 文件。

<script lang="ts">import "./app.css";import Layout from "@/layout/Layout.svelte";import Router from "@/router/Router.svelte";import { locale } from "svelte-i18n";import Toast from "./components/Toast.svelte";import { toast } from "@/utils/toastService";// 引入阿里图标import '../public/iconfont/iconfont.css';
</script>

9.4 使用图标

在 Svelte 组件中使用阿里图标,直接通过 class 引用图标类名。

<div><i class="iconfont icon-home"></i> <!-- icon-home 是图标类名 --><i class="iconfont icon-user"></i> <!-- icon-user 是图标类名 -->
</div>

9.5 动态切换图标

如果需要动态切换图标,可以将图标类名绑定到变量。

<script lang="ts">let iconClass = 'icon-home';
</script><div><i class={`iconfont ${iconClass}`}></i><button on:click={() => iconClass = 'icon-user'}>切换图标</button>
</div>

9.6 使用 Symbol 方式(可选)

如果选择 Symbol 方式,需要引入 iconfont.js 文件,并使用 <svg> 标签。

<script lang="ts">import '../public/iconfont/iconfont.js';
</script><svg class="icon" aria-hidden="true"><use xlink:href="#icon-home"></use> <!-- #icon-home 是图标 ID -->
</svg>

9.7 样式调整(可选)

如果需要调整图标大小或颜色,可以通过 CSS 设置。

<style lang="less">.iconfont {font-size: 24px;color: #333;}
</style>

9.8 示例代码

以下是一个完整的示例:

<script lang="ts">import "./app.css";import Layout from "@/layout/Layout.svelte";import Router from "@/router/Router.svelte";import { locale } from "svelte-i18n";import Toast from "./components/Toast.svelte";import { toast } from "@/utils/toastService";// 引入阿里图标import '../public/iconfont/iconfont.css';let iconClass = 'icon-home';
</script>{#if $locale}<Layout><Router /></Layout>{#if $toast.visible}<Toast message={$toast.message} />{/if}
{/if}<div><i class={`iconfont ${iconClass}`}></i><button on:click={() => iconClass = 'icon-user'}>切换图标</button>
</div><style lang="less">.iconfont {font-size: 24px;color: #333;}
</style>

通过以上步骤,你可以在 Svelte 项目中成功使用阿里图标。如果需要更多定制化功能,可以参考 iconfont 官方文档。

十、svelte轮播图

这里用的是https://3.swiper.com.cn/
下载引入相关css与js即可
demo如下

<script>import { onMount } from 'svelte';import  '@/utils/swiper/swiper.min.js';import '@/utils/swiper/swiper.min.css';let swiperInstance;onMount(() => {// 初始化 SwiperswiperInstance = new Swiper('.swiper-container', {pagination: '.swiper-pagination',paginationClickable: true,autoplay:2500,loop:true});});</script><style>html, body {position: relative;height: 100%;}body {background: #eee;font-family: Helvetica Neue, Helvetica, Arial, sans-serif;font-size: 14px;color:#000;margin: 0;padding: 0;}.swiper-container {width: 100%;height: 350px;}.swiper-slide {text-align: center;font-size: 18px;background: #fff;/* Center slide text vertically */display: -webkit-box;display: -ms-flexbox;display: -webkit-flex;display: flex;-webkit-box-pack: center;-ms-flex-pack: center;-webkit-justify-content: center;justify-content: center;-webkit-box-align: center;-ms-flex-align: center;-webkit-align-items: center;align-items: center;}</style><!-- Swiper --><div class="swiper-container"><div class="swiper-wrapper"><div class="swiper-slide">Slide 1</div><div class="swiper-slide">Slide 2</div></div><!-- Add Pagination --><div class="swiper-pagination"></div>
</div>

十一、store数据共享

在 Svelte 中,store 是一个核心概念,用于管理应用的状态。为了更好地组织代码,可以将 store 封装为模块,包括 stateactionsgettersmutations,类似于 Vuex 或 Redux 的设计模式。以下是如何封装 store 的示例:


1. 创建 store 模块

src/store 目录下创建一个模块,例如 centerStore.ts,用于管理特定模块的状态和逻辑。

// src/store/centerStore.ts
import { writable, derived } from 'svelte/store';// State
const state = writable({userData: null,loading: false,error: null,
});// Actions
const actions = {async getUserData(params: { onlyMakeTheSame: boolean }) {try {state.update((s) => ({ ...s, loading: true, error: null }));// 模拟 API 调用const response = await fetch('/api/user', { method: 'GET' });const data = await response.json();state.update((s) => ({ ...s, userData: data, loading: false }));} catch (error) {state.update((s) => ({ ...s, error: error.message, loading: false }));}},
};// Getters
const getters = {userData: derived(state, ($state) => $state.userData),isLoading: derived(state, ($state) => $state.loading),error: derived(state, ($state) => $state.error),
};// Mutations (可选)
const mutations = {setUserData(userData: any) {state.update((s) => ({ ...s, userData }));},
};// 导出模块
export const centerStore = {state,actions,getters,mutations,
};

2. 创建全局 store

src/store/index.ts 中整合所有模块,创建一个全局 store

// src/store/index.ts
import { centerStore } from './centerStore';export const store = {center: centerStore,
};

3. 在组件中使用 store

在 Svelte 组件中导入并使用 store

<script lang="ts">import { store } from '@/store/index';import { onMount } from 'svelte';// 获取 state 和 gettersconst { state, getters } = store.center;// 调用 actionfunction fetchData() {store.center.actions.getUserData({ onlyMakeTheSame: false });}onMount(() => {fetchData();});
</script>{#if $getters.isLoading}<p>Loading...</p>
{:else if $getters.error}<p style="color: red;">Error: {$getters.error}</p>
{:else if $getters.userData}<div><h1>User Data</h1><pre>{JSON.stringify($getters.userData, null, 2)}</pre></div>
{/if}<button on:click={fetchData}>Refresh Data</button>

4. 封装 store 的优势

  • 模块化:将状态和逻辑按模块划分,便于维护和扩展。
  • 复用性actionsgetters 可以在多个组件中复用。
  • 可测试性actionsmutations 可以单独测试。
  • 清晰性stateactionsgettersmutations 分离,代码结构更清晰。

5. 示例:about.svelte 中使用 store

根据你的 about.svelte 文件,可以这样使用 store

<script lang="ts">import { t, locale } from "svelte-i18n";import { toast } from '@/utils/toastService';import { store } from '@/store/index';function getData() {store.center.actions.getUserData({ onlyMakeTheSame: false });}
</script><h1>{$t("welcome")}</h1>
<p>{$t("about")}</p><button on:click={getData}>获取接口数据</button>{#if $store.center.getters.isLoading}<p>Loading...</p>
{:else if $store.center.getters.error}<p style="color: red;">Error: {$store.center.getters.error}</p>
{:else if $store.center.getters.userData}<div><h1>User Data</h1><pre>{JSON.stringify($store.center.getters.userData, null, 2)}</pre></div>
{/if}

通过以上步骤,你可以在 Svelte 项目中封装 store,并实现 stateactionsgettersmutations 的分离,使代码更易于维护和扩展。

十二、扩展内容

这里由于使用的melt-ui没有toast提示于是做了一个全局组建toas.svelte

  1. 组建创建
<script>import { fade } from "svelte/transition";export let message = "";export let duration = 3000; // 持续时间,单位毫秒let visible = false;const showToast = () => {visible = true;setTimeout(() => {visible = false;}, duration);};showToast(); // 显示Toast
</script>{#if visible}<div class="toast" transition:fade>{message}</div>
{/if}<style>.toast {position: fixed;top: 300px;left: 50%;transform: translateX(-50%);padding: 10px 20px;background-color: #333;color: white;border-radius: 5px;z-index: 1000;}
</style>
  1. toastService封装
import { writable } from 'svelte/store';
function createToast() {const { subscribe, set, update } = writable({ message: '', visible: false });function show(message, duration = 3000) {set({ message, visible: true });setTimeout(() => {update(current => ({ ...current, visible: false }));}, duration);}return {subscribe,show, // 公开show方法供外部调用};
}export const toast = createToast(); // 创建并导出toast服务实例
  1. 全局调用app.svelte
<script lang="ts">import Toast from "./components/Toast.svelte";import { toast } from "@/utils/toastService";
</script>{#if $toast.visible}<!-- 使用$来访问store的值 --><Toast message={$toast.message} /><!-- 将消息传递给Toast组件 -->{/if}
  1. 使用
  import { toast } from '@/utils/toastService';toast.show('Hello, this is a toast!')

十三、框架git地址

https://gitee.com/cyp926/svelte-vite

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/75999.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

无法看到新安装的 JDK 17

在 Linux 系统中使用 update-alternatives --config java 无法看到新安装的 JDK 17&#xff0c;可能是由于 JDK 未正确注册到系统备选列表中。 一、原因分析 JDK 未注册到 update-alternatives update-alternatives 工具需要手动注册 JDK 路径后才能识别新版本。如果仅安装 JDK…

鼎讯信通 便携式雷达信号干扰模拟器:打造实战化电磁环境的新利器

在现代战争中&#xff0c;电磁环境的复杂性直接影响着雷达装备的性能和作战效果。面对敌方日益精进的电子战手段&#xff0c;如何提升雷达设备的抗干扰能力&#xff0c;确保其在实战环境中的稳定性和可靠性&#xff0c;已成为各国军队和科研机构的重要课题。 为此&#xff0c;…

【AI提示词】决策专家

提示说明 决策专家可以帮助你进行科学决策&#xff0c;尽可能避免错误&#xff0c;提升决策成功的概率。 提示词 # Role : 决策专家决策&#xff0c;是面对不容易判断优劣的几个选项&#xff0c;做出正确的选择。说白了&#xff0c;决策就是拿个主意。决策专家是基于科学决策…

力扣Hot100题,刷题

力扣HOT100 - 1. 两数之和 解题思路&#xff1a; 解法一&#xff1a;暴力 class Solution {public int[] twoSum(int[] nums, int target) {int n nums.length;for (int i 0; i < n; i)for (int j i 1; j < n; j) {if (target nums[i] nums[j])return new int[]…

uni-app ucharts自定义换行tooltips

实现效果&#xff1a; 第一步&#xff1a;在uni_modules文件夹下找到config-ucharts.js和u-charts.js文件 第二步&#xff1a;在config-ucharts.js文件中配置换行格式 // 换行格式"wrapTooltip":function(item, category, index, opts){return item.name&#xff1a;…

国标GB28181视频平台EasyCVR顺应智慧农业自动化趋势,打造大棚实时视频监控防线

一、方案背景 近年来&#xff0c;温室大棚种植技术凭借其显著的优势&#xff0c;在提升农作物产量和质量、丰富农产品供应方面发挥了重要的作用&#xff0c;极大改善了人们的生活水平&#xff0c;得到了广泛的推广和应用。大棚内的温度、湿度、光照度和二氧化碳浓度等环境因素…

InternVideo2.5:Empowering Video MLLMs with Long and Rich Context Modeling

一、TL&#xff1b;DR InternVideo2.5通过LRC建模来提升MLLM的性能。层次化token压缩和任务偏好优化&#xff08;mask时空 head&#xff09;整合到一个框架中&#xff0c;并通过自适应层次化token压缩来开发紧凑的时空表征MVBench/Perception Test/EgoSchema/MLVU数据benchmar…

【时时三省】(C语言基础)条件运算符和条件表达式

山不在高&#xff0c;有仙则名。水不在深&#xff0c;有龙则灵。 ----CSDN 时时三省 有一种if语句&#xff0c;当被判别的表达式的值为“真”或“假”时&#xff0c;都执行一个赋值语句且向一个变量赋值。 如&#xff1a; if ( a > b ) max a&#xff1b; else max …

KWDB创作者计划—边缘计算:从概念到落地的技术解读

引言 随着物联网&#xff08;IoT&#xff09;和人工智能&#xff08;AI&#xff09;的快速发展&#xff0c;数据量呈爆炸式增长&#xff0c;传统的云计算架构逐渐暴露出延迟高、带宽占用大等问题。边缘计算作为一种新兴的分布式计算范式&#xff0c;正在改变数据处理的方式。本…

蓝桥杯基础算法-递归

代码简洁&#xff0c;但涉及到的运算&#xff0c;会随着递归层数的增加成指数级增长 路分析&#xff1a;第20行20列位于45度这条线上 这条线上的数字是1 5 13 25 41...两数之差:4 8 12 16 --->每一个都是在前面的基础上4&#xff0c;可以用递归或者循环 public class dem…

通过学习opencv图像库编程借助第三方库函数完成一个综合程序设计

通过学习opencv图像库编程借助第三方库函数完成一个综合程序设计 1) 编译命令解释&#xff1a; 编译命令&#xff1a; gcc test1.cpp -o test1 pkg-config --cflags --libs opencv这条命令包含了以下部分&#xff1a; gcc test1.cpp -o test1: gcc 是 GNU 编译器集合&#…

第十四届蓝桥杯大赛软件赛国赛C/C++研究生组

研究生C国赛软件大赛 题一&#xff1a;混乘数字题二&#xff1a;钉板上的正方形题三&#xff1a;整数变换题四&#xff1a;躲炮弹题五&#xff1a;最大区间 题一&#xff1a;混乘数字 有一点像哈希表&#xff1a; 首先定义两个数组&#xff0c;拆分ab和n 然后令n a*b 查看两个…

系统与网络安全------网络通信原理(2)

资料整理于网络资料、书本资料、AI&#xff0c;仅供个人学习参考。 物理层解析 物理层概述 物理层是TCP/IP模型的最底层物理层数据传输提供稳定的物理连接 物理层功能 定义设备的物理连接的标准和特性&#xff0c;比如接口形状&#xff0c;大小定义电气特性&#xff0c;高低…

内容中台的数字化管理核心是什么?

数字化整合与系统协同 现代企业的内容管理正经历从分散式架构向数字化整合的范式转变。通过将内容管理系统与文档管理技术深度耦合&#xff0c;组织能够打破数据孤岛&#xff0c;实现跨部门、跨平台的资源互通。例如&#xff0c;基于元数据分类的标准化体系&#xff0c;不仅提…

Python爬虫第二战(使用xpath爬取网站数据)

本文是我在学习过程中记录学习的点点滴滴&#xff0c;目的是为了学完之后巩固一下顺便也和大家分享一下&#xff0c;日后忘记了也可以方便快速的复习。 使用xpath爬取猪八戒网站数据 前言 前言 今天学习的主要是关于Python使用xpath来爬取猪八戒网的网页知识的理解和应用 #1.获…

进程同步和进程互斥的区别

如大家所了解的&#xff0c;进程互斥是由互斥资源引起的&#xff0c;即各进程之间共享互斥资源的使用权&#xff0c;这种竞争没有确定的必然联系&#xff0c;哪个进程竞争到互斥资源的使用权&#xff0c;则该资源就归哪个进程使用&#xff0c;从而获得所需资源的进程就可以获得…

ArkTS语言基础之函数

前言 臭宝们终于来到了ArkTS基础之函数&#xff0c;今天我们来学习一下ArkTS的函数的相关知识&#xff0c;上一节中也有一些函数的基础知识。 函数声明 函数声明引入一个函数&#xff0c;包含其名称、参数列表、返回类型和函数体,在下面的例子中&#xff0c;我们声明了一个名…

redis中的hash

Redis中的hash是什么 Hash: 哈希&#xff0c;也叫散列&#xff0c;是一种通过哈希函数将键映射到表中位置的数据结构&#xff0c;哈希函数是关键&#xff0c;它把键转换成索引。 Redis Hash&#xff08;散列表&#xff09;是一种 field-value pairs&#xff08;键值对&#x…

弹簧质点系统(C++实现)

本文实现一个简单的物理算法&#xff1a;弹簧质点系统&#xff08;Mass-Spring System&#xff09;。这是一个经典的物理模拟算法&#xff0c;常用于模拟弹性物体&#xff08;如布料、弹簧等&#xff09;的行为。我们将使用C来实现这个算法&#xff0c;并结合链表数据结构来管理…

领域大模型

领域技术标准文档或领域相关数据是领域模型Continue PreTrain的关键。 现有大模型在预训练过程中都会加入书籍、论文等数据&#xff0c;那么在领域预训练时这两种数据其实也是必不可少的&#xff0c;主要是因为这些数据的数据质量较高、领域强相关、知识覆盖率&#xff08;密度…