• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

vue3 tsx语法

武飞扬头像
yangliweigauguagua
帮助1

1,v-model

tsx语法也可以使用v-model语法来绑定变量

学新通

 2,事件 @click,@change

tsx语法统一把@符号变成on 事件名称的格式

学新通

3,属性,slot,emit位置

vue3组件获取props,slots,emits统一在setup方法中拿到

学新通

4, 插槽

tsx语法的组件插槽和传统的vue语法存在很大不同

传统插槽:

学新通

 在tsx语法中,插槽要这么写

学新通

 5,注意事项

 tsx组件只有一个根节点

tsx变量直接使用大括号,不需要使用v-bind

tsx在大括号中写代码语句,在圆括号中写jsx语法

6,例子: 一个封装的editor组件

  1.  
    import { defineComponent, ref } from "vue";
  2.  
    import { QuillEditor } from "@vueup/vue-quill";
  3.  
    import "@vueup/vue-quill/dist/vue-quill.snow.css";
  4.  
    import ImageUploader from "quill-image-uploader";
  5.  
    import { upload } from "@/api";
  6.  
     
  7.  
    export default defineComponent({
  8.  
    props: {
  9.  
    modelValue: {
  10.  
    type: String,
  11.  
    default: () => "",
  12.  
    },
  13.  
    },
  14.  
    emits: ["update:modelValue"],
  15.  
    setup(props, { emit }) {
  16.  
    const content = ref(props.modelValue);
  17.  
    const updateContent = (content: any) => {
  18.  
    emit("update:modelValue", content);
  19.  
    };
  20.  
    const modules = {
  21.  
    name: "imageUploader",
  22.  
    module: ImageUploader,
  23.  
    options: {
  24.  
    upload: async (file: any) => {
  25.  
    const res = await upload(file);
  26.  
    return res.data.url;
  27.  
    },
  28.  
    },
  29.  
    };
  30.  
    return () => (
  31.  
    <QuillEditor
  32.  
    toolbar="full"
  33.  
    v-model:content={content.value}
  34.  
    contentType="html"
  35.  
    modules={modules}
  36.  
    style="max-height: 300px"
  37.  
    onUpdate:content={updateContent}
  38.  
    />
  39.  
    );
  40.  
    },
  41.  
    });
学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgbeeae
系列文章
更多 icon
同类精品
更多 icon
继续加载