首页 > 其他分享 >vite+jsx

vite+jsx

时间:2024-04-28 10:35:56浏览次数:10  
标签:vue const jsx value ref vite

"@vitejs/plugin-vue-jsx": "^3.1.0"

vite配置

import vueJsx from '@vitejs/plugin-vue-jsx' // 添加这一句

// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
vueJsx() // 添加这一句
]
})

"vite": "3.0.0", "compilerOptions": {     "jsx": "preserve", }  第一种写法 test.jsx import { defineComponent, ref } from "vue";
const TestJsx = defineComponent({     emits: ['click', 'getDate'],     setup(props, {emit}) {         const val = ref('this is a input');         const userName = ref('this is a username');         const handleInputChange = (e) => { val.value = e.target.value }         const handleClick = () => {             alert("this is a button")             emit("click")         }         const vnode = <div>hello, {userName.value}</div>         const list = [1, 2, 3]         return () => <>             <div>{val.value}</div>             {list.map(item => <div onclick={handleClick}>{item}</div>)}             {vnode}         </>     } })


export default TestJsx

 

第二种写法
test.vue
// render.vue
<script lang="jsx">
import { ref } from "vue";
import { defineComponent } from 'vue'
export default {
  setup() {
    const count = ref(100);
    return () => <div>count is: {count.value}</div>;
  },
};
</script>

 

 在实现业务需求的时候,优先使用 template,尽可能地利用 Vue 本身的性能优化。而对于动态性要求较高的组件可以使用 JSX 来实现。(比如后面,我会用JSX来实现动态表单生成器)

标签:vue,const,jsx,value,ref,vite
From: https://www.cnblogs.com/shuangzikun/p/18144274

相关文章

  • vue3+vite+js 引用public文件夹中js文件
    vue的public的资源在打包时不会被编译,只会copy所以在在src路径下引入public文件夹下的图片、视频、音频,编译不会改变其路径,但是在src下引入public文件夹下的js、json,在打包时都会被编译,所以直接引入会丢失路径(因为打包时,当前页面引入的路径被hash打包,而public文件夹下只是被cop......
  • vite打包,pdfjs-dist 报错import引入pdfjs-dist报错Top-level await is not available
    Top-levelawaitisnotavailableintheconfiguredtargetenvironment("chrome87","edge88","es2020","firefox78","safari14"+2overrides)node_modules/pdfjs-dist/build/pdf.mjs:17349:53:17349│/****......
  • 前端【TS】02-typescript【基础】【搭建Vite+Vue3+TS项目】【为ref标注类型】
    前置基于Vite创建Vue3+TS环境vite官方文档:https://cn.vitejs.dev/guide/vite除了支持基础阶段的纯TS环境之外,还支持Vue+TS开发环境的快速创建,命令如下:1npmcreatevite@latestvue-ts-project----templatevue-ts23//说明:41.npmcreatevite@lates......
  • 何时使用JSX.Element vs ReactNode vs ReactElement?
    在React开发中,JSX.Element、ReactNode和ReactElement这三个类型分别代表不同级别的React组件树中的元素,它们在不同的上下文中有着各自的用途。以下是它们的区别及使用场景的概述:JSX.Element定义:JSX.Element是当你编写JSX语法时,编译器(如Babel)将这些语法转化为等效的Reac......
  • 新建vite vue2 项目
    1.1创建项目注意:这里vite的版本采用2.8.0的,最新的版本创建后续会出现问题[email protected]后续,安装如图  创建好项目后依次运行以下命令//1.进入项目cdvite-vue2​//2.安装依赖npminstall​//3.启动项目npmrundev访问效果如下  1.2安装vite对vue2支持......
  • vitepress搭建博客
    vitepress搭建博客之前使用的Hugo搭建了一个博客,感兴趣的可以看看Hugo搭建个人博客,使用了一段时间,配置完成后使用还是相对简单的,不过总感觉不够顺手,后来看到vitepress,就尝试了一下,感觉使用更顺手一些,所以打算换成vitepress,下面记录一下搭建的过程。搭建博客流程关于使用vitep......
  • Vue3 + vite 项目自定义一个svg-icon组件
    1.安装vite-plugin-svg-icons插件npmivite-plugin-svg-icons-D2.vite.config.ts中配置importpathfrom"path";import{createSvgIconsPlugin}from"vite-plugin-svg-icons";exportdefaultdefineConfig({plugins:[......createS......
  • VUE:vite添加环境变量(一)
    新建'.env'(和vite.config.js同一个路径下)VITE_APP_API_URL=http://localhostvite.config.jsimport{defineConfig,loadEnv}from'vite'exportdefaultdefineConfig((mode)=>{constenv_config=loadEnv(mode,process.cwd())constV......
  • vite和webpack对比
    定位分析打包工具:webpack、rollup、parcel、esbuild作用:可以对代码进行压缩、合并、转换、分割、打包衍生:vue-cli、create-react-app、umi等是基于webpack的上层封装,用于快速创建项目vite:开发环境依赖esbuild进行预构建,生产环境则依赖rollup进行打包差异分析1、启动差异we......
  • vite+xlsx-style表格导出样式设置报错
    项目是vite+vue3,前端表格导出,使用xlsx可以导出基本表格,但是想要设置表格样式,引入xlsx-style,安装依赖,后引入报错引用import { utils } from "xlsx"import { write } from "xlsx-style"Couldnotresolve"./cptable"node_modules/xlsx-style/dist/cpexce......