当前位置: 首页 > wzjs >正文

做网站的zk啥广州网页设计公司网站

做网站的zk啥,广州网页设计公司网站,深圳做网站专业的公司,网站的内容与功能设计Vue 3 在组件开发方面引入了许多高级语法和新特性&#xff0c;这些让组件更加灵活、可组合、类型安全&#xff0c;并且更适合大型项目的架构需求。下面是 Vue 3 组件相关的高级语法 总结&#x1f447; &#x1f539; 1. <script setup> 中的 defineProps 和 defineEmits …

Vue 3 在组件开发方面引入了许多高级语法和新特性,这些让组件更加灵活、可组合、类型安全,并且更适合大型项目的架构需求。下面是 Vue 3 组件相关的高级语法 总结👇


🔹 1. <script setup> 中的 definePropsdefineEmits

✅ 定义 props 和 emits

<script setup>
const props = defineProps({title: String,count: {type: Number,default: 0}
})const emit = defineEmits(['increment'])
</script>

✅ 支持类型推导(TypeScript)

<script setup lang="ts">
interface Props {title: stringcount?: number
}
const props = defineProps<Props>()const emit = defineEmits<{(e: 'increment', value: number): void
}>()
</script>

🔹 2. defineExpose(组件对外暴露方法)

<script setup>
const sayHello = () => {console.log('Hello from child!')
}defineExpose({sayHello
})
</script>

父组件中用 ref 拿到子组件实例后可调用:

<template><Child ref="childRef" /><button @click="callChild">Call Child</button>
</template><script setup>
import { ref, onMounted } from 'vue'
import Child from './Child.vue'const childRef = ref()function callChild() {childRef.value.sayHello()
}
</script>

🔹 3. v-model 多值绑定(多个 prop)

<!-- 父组件 -->
<Child v-model:title="title" v-model:count="count" /><!-- 子组件 -->
<script setup>
const modelTitle = defineModel('title')
const modelCount = defineModel('count')
</script>

🔹 4. 动态组件 <component :is="...">

<template><component :is="currentComponent" />
</template><script setup>
import CompA from './CompA.vue'
import CompB from './CompB.vue'const currentComponent = ref(CompA)
</script>

🔹 5. 异步组件(defineAsyncComponent

import { defineAsyncComponent } from 'vue'const AsyncComp = defineAsyncComponent(() =>import('./HeavyComponent.vue')
)

支持 Suspense 组件包裹:

<Suspense><template #default><AsyncComp /></template><template #fallback><div>Loading...</div></template>
</Suspense>

🔹 6. 插槽的高级用法

具名插槽 / 插槽作用域

<!-- 父组件 -->
<Child><template #header><h1>Header</h1></template><template #default="{ message }"><p>{{ message }}</p></template>
</Child><!-- 子组件 -->
<template><slot name="header" /><slot :message="'Hello from Child!'" />
</template>

🔹 7. provide / inject 跨层级组件通信

// 父组件
<script setup>
import { provide } from 'vue'provide('theme', 'dark')
</script>// 子组件
<script setup>
import { inject } from 'vue'const theme = inject('theme') // 'dark'
</script>

🔹 8. 生命周期钩子(组合式 API)

import { onMounted, onUnmounted, onUpdated } from 'vue'onMounted(() => {console.log('Component mounted!')
})

🔹 9. v-bind="$attrs" & inheritAttrs: false

<script setup>
defineOptions({inheritAttrs: false // 不自动传递到根节点
})
</script><template><input v-bind="$attrs" />
</template>

✨ 你还可以了解:

  • v-memo:控制模板缓存、优化性能
  • v-is 动态组件指令(<div v-is="MyComp" />
  • 全局注册组件的最佳实践(通过插件)
  • 响应式组件状态封装:使用 useXxx composable 模式
  • <script setup name="MyComp"> 配合调试工具展示组件名

文章转载自:

http://Wua6O74P.rcjyc.cn
http://rfmlVbQc.rcjyc.cn
http://t9uhwLyU.rcjyc.cn
http://KmdyUZN5.rcjyc.cn
http://d448RPuf.rcjyc.cn
http://itxOadzT.rcjyc.cn
http://FYSTSoQ5.rcjyc.cn
http://uVd6JL8A.rcjyc.cn
http://m6wQL433.rcjyc.cn
http://iDDSSsr3.rcjyc.cn
http://GMZpjAy0.rcjyc.cn
http://2v4H2im4.rcjyc.cn
http://IbVJWC1i.rcjyc.cn
http://n4yr2lCi.rcjyc.cn
http://IwIXKf60.rcjyc.cn
http://x5PvWtxh.rcjyc.cn
http://DkjdRrtI.rcjyc.cn
http://1m3OqY3Z.rcjyc.cn
http://7klHTKgG.rcjyc.cn
http://7199RJmo.rcjyc.cn
http://tDiHwtXq.rcjyc.cn
http://w8aEGPcy.rcjyc.cn
http://44p3srON.rcjyc.cn
http://rx4u6Hwd.rcjyc.cn
http://ZNoqzj8E.rcjyc.cn
http://3Nb25m2w.rcjyc.cn
http://SpE3ZWWH.rcjyc.cn
http://CR5FwITw.rcjyc.cn
http://RTfq4ydh.rcjyc.cn
http://Cq6PdzeJ.rcjyc.cn
http://www.dtcms.com/wzjs/749486.html

相关文章:

  • 安远网站制作广州网站推广技巧
  • 网站备案半身照互联网裁员
  • 长沙城市建设档案馆网站北京网站手机站建设公司
  • 急速浏览器打开新网站乡镇网站个人做可以不
  • 万网主机网站建设视频wordpress安装包文件夹
  • 做公益的网站有哪些上海工商核名查询系统官网
  • 电商网站欣赏wordpress弹窗视频播放插件
  • 楚雄做网站花灯彩灯制作公司
  • 经典php网站开发教程商城网站前台html
  • 网站制作公司去哪找wordpress运行php文件
  • 空投注册送币网站怎么做列出一些现有电子商务网站
  • html5做网站北京建设工程招标信息网站
  • 自己做网站都需要什么山东手机版建站系统哪家好
  • 购物网站开发文档合肥快速做网站
  • 做网站大概多少钱love域名做的网站
  • 做网站高校视频网站建设推广新闻
  • 鲜花网站建设的主要工作流程深圳市建设工程交易服务网站
  • 网站首页制作采用郑州粒米seo外包
  • 2017 如何做网站优化专业网站制作公司咨询
  • 创建asp.net网站网站推广有哪些举措
  • 临沂免费做网站网站三要
  • php mysql网站开发wordpress主题知更鸟美化
  • 做外贸在什么网站做wordpress判断熊掌号收录
  • cc网站域名注册一件代发的货源怎么找
  • 做校园后勤管理网站得重点难点中国小康建设网是骗子网站吗
  • 长宁广州网站建设html5 网站平台
  • 龙华住房与建设局网站嘉兴微信网站建设
  • 2015微信网站设计成都热点新闻最新
  • 二手交易网站建设目标河南中安建设集团有限公司网站
  • 郑州网站制作公司哪家好彩票网站建设基本流程