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

移动电商网站开发需求海南企业年报网上申报入口

移动电商网站开发需求,海南企业年报网上申报入口,绍兴兴住房和城乡建设局网站,wordpress 文章形式为什么要有setup语法糖: 在选择式API中,一个模块涉及到的数据、方法、声明周期,会比较分撒,位置不集中,不利于解读代码,但是组合式API中的setup函数可以将他们组织在一起,提高了代码的可维护性…

为什么要有setup语法糖:

在选择式API中,一个模块涉及到的数据、方法、声明周期,会比较分撒,位置不集中,不利于解读代码,但是组合式API中的setup函数可以将他们组织在一起,提高了代码的可维护性以及复用性,但是每次使用都要写setup函数,还需要将变量返回,所以引入了setup语法糖

setup函数原始写法:

<script>
export default{setup(){const message = 'This is message'const logMessage=()=>{console.log(message)}return{message,logMessage}}
}
<script>

setup函数的用法:

setup函数他的执行时机比beforeCreate更早,所以在setup函数中this的返回值是undefind,因此在setup函数中不使用this,

使用setup组件自动注册

注意下面对比

需要手动注册(在选择式API中)

<script>import ChildComponent from './ChildComponent.vue'export default{component:{ChildComponent}}
</script>
<template><ChildComponent />
</template>

自动注册(组合式API)

<script setup>import ChildComponent from './ChildComponent.vue'
</script>
<template><ChildComponent />
</template>

一般情况下,会自动注册,但是下面三种情况需要注意

动态组件((需用 resolveComponent))

<script setup>
import { resolveComponent } from 'vue'
​
const componentName = 'ChildComponent'
const ChildComponent = resolveComponent(componentName)
</script>
​
<template><component :is="ChildComponent" />
</template>

递归组件(需显式引用自身)

<!-- TreeItem.vue -->
<script setup>
import TreeItem from './TreeItem.vue' // 导入自身
​
defineProps({data: Object
})
</script>
<template><div>{{ data.name }}<TreeItem v-for="child in data.children" :key="child.id" :data="child" /></div>
</template>

全局组件(需通过 app.component 注册)

// main.ts
import { createApp } from 'vue'
import GlobalButton from './components/GlobalButton.vue'
​
const app = createApp(App)
app.component('GlobalButton', GlobalButton) // 全局注册

<script setup> 是 Vue 3 为 Composition API 设计的一种编译时语法糖,它通过更简洁的语法结构实现了与传统 setup() 函数相同的功能,但大幅减少了样板代码。使用这种语法时,所有顶层绑定的变量、函数和组件导入都会自动暴露给模板,无需手动返回对象;响应式数据(如 ref/reactive)可直接在模板中使用,组件也无需显式注册即可引用。同时它天然支持 TypeScript 类型推导,保留了完整的 Composition API 逻辑组织能力,让开发者既能保持关注点分离的优势,又能获得类似 Svelte 的简洁开发体验,最终编译时会转换为标准的组件选项语法,是 Vue 3 单文件组件开发的推荐模式。

动态组件

什么是动态组件: 最开始出现动态组件是在vue1版本中,解释如下:

动态组件:多个组件可以使用同一个挂载点,然后动态地在它们之间切换。使用保留的 <component> 元素,动态地绑定到它的 is 特性

new Vue({el: 'body',data: {currentView: 'home'},components: {home: { /* ... */ },posts: { /* ... */ },archive: { /* ... */ }}
})
​
<component :is="currentView"><!-- 组件在 vm.currentview 变化时改变 -->
</component>

如果把切换出去的组件保留在内存中,可以保留它的状态或避免重新渲染。为此可以添加一个 keep-alive 指令参数:

<component :is="currentView" keep-alive><!-- 非活动组件将被缓存 -->
</component>

文章转载自:

http://00000000.rtsgx.cn
http://00000000.rtsgx.cn
http://00000000.rtsgx.cn
http://00000000.rtsgx.cn
http://00000000.rtsgx.cn
http://00000000.rtsgx.cn
http://00000000.rtsgx.cn
http://00000000.rtsgx.cn
http://00000000.rtsgx.cn
http://00000000.rtsgx.cn
http://00000000.rtsgx.cn
http://00000000.rtsgx.cn
http://00000000.rtsgx.cn
http://00000000.rtsgx.cn
http://00000000.rtsgx.cn
http://00000000.rtsgx.cn
http://00000000.rtsgx.cn
http://00000000.rtsgx.cn
http://00000000.rtsgx.cn
http://00000000.rtsgx.cn
http://00000000.rtsgx.cn
http://00000000.rtsgx.cn
http://00000000.rtsgx.cn
http://00000000.rtsgx.cn
http://00000000.rtsgx.cn
http://00000000.rtsgx.cn
http://00000000.rtsgx.cn
http://00000000.rtsgx.cn
http://00000000.rtsgx.cn
http://00000000.rtsgx.cn
http://www.dtcms.com/wzjs/620942.html

相关文章:

  • wap网站建设免费泰兴建设局网站
  • 网站做描本好处怎么用百度云做网站空间
  • 潍坊网站建设教程个人律师网站模板
  • 导航网站没有内页没有了学生没钱怎么开网店
  • python做电子商务网站网站建设 dw
  • 黄石有哪些做视觉网站的公司用户网站模板
  • 做网站每年包多少流量wordpress 不用主题
  • 付公司网站费用怎么做分录wordpress wp play
  • 用jsp做网站主界面建筑工程网课文案
  • 建网站哪便宜12306网站为什么做不好使
  • 产品设计私单网站企业 北京 响应式网站
  • 上海模板建站软件重庆seo优化公司哪家好
  • app网站建设公司在线设计装修户型图
  • 做a小视频网站济南做网站公司哪家好
  • 福建建设工程环保备案网站入口匈牙利网站后缀
  • 网站开发游戏程序开发焦作做网站公司
  • 设计网站与建设网页被禁止浏览怎么解决
  • 长沙长沙网站建设大数据精准营销服务
  • godaddy上传网站网站首页菜单栏表怎么做
  • 网站做搜索关键字好吗网站的风格包含的因素
  • sem推广平台有哪些信息流优化师招聘
  • 网站上传可以通过html页面跳转
  • 上饶哪有做网站的公司可以制作网站的软件是什么
  • 网站开发建设公司电话创建微信公众号步骤
  • asp.net mvc 5网站开发之美 pdf个人做搜索网站违法吗
  • wordpress企业网站入门vs简易新闻建设网站
  • 阿里云ace+wordpress优化设计电子课本
  • 网站开发登录要做哪些验证互联网推广企业
  • 网上怎么做网站深圳vi设计公司哪家专业
  • 寮步营销型网站建设网站内容维护费用