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

碧海蓝天网站h5制作模板官网

碧海蓝天网站,h5制作模板官网,重庆网站开发设计公司,c2c交易平台官网组件基础 每一个.vue 文件都可以充当组件来使用 每一个组件都可以复用 父组件引入之后可以直接当标签使用 案例#xff1a; App.vue script setup langts import BaseRefAndReactive from ./components/BaseRefAndReactive.vue;/sc…组件基础 每一个.vue 文件都可以充当组件来使用 每一个组件都可以复用 父组件引入之后可以直接当标签使用 案例 App.vue script setup langts import BaseRefAndReactive from ./components/BaseRefAndReactive.vue;/scripttemplateBaseRefAndReactive/BaseRefAndReactive/templatestyle scoped/style组件的生命周期 也就是一个组件从创建到更新最后销毁的过程 在我们使用Vue3 组合式API 是没有 beforeCreate 和 created 这两个生命周期的也就是在使用setup语法糖时 常用的生命周期钩子主要有以下六个 onBeforeMount() 在组件DOM实际渲染安装之前调用。在这一步中dom元素还不存在。 onMounted() 在组件的第一次渲染后调用该元素现在可用允许直接DOM访问 onBeforeUpdate() 数据更新时调用发生在虚拟 DOM 打补丁之前。也就是真实dom尚未更新 onUpdated() DOM更新后updated的方法即会调用。 onBeforeUnmount() 在卸载组件实例之前调用。在这个阶段实例仍然是完全正常的。 onUnmounted() 卸载组件实例后调用。调用此钩子时组件实例的所有指令都被解除绑定所有事件侦听器都被移除所有子组件实例被卸载。 案例 App.vue script setup langts import BaseRefAndReactive from ./components/BaseRefAndReactive.vue; import {ref} from vue; let flag ref(true);/scripttemplateBaseRefAndReactive v-ifflag/BaseRefAndReactivebutton clickflag !flag点我测试/button /templatestyle scoped/style组件内 script setup langts import { ref, Ref,onBeforeMount,onMounted,onBeforeUpdate,onUpdated,onBeforeUnmount,onUnmounted } from vue const refData ref(我是组件哈哈哈) const divText ref(我是div) let div:RefHTMLDivElement | null ref(null) onBeforeMount((){console.log(onBeforeMount,div.value) }) onMounted((){console.log(onMounted,div.value) }) onBeforeUpdate((){console.log(onBeforeUpdate,div.value?.innerHTML) }) onUpdated((){console.log(onUpdated,div.value?.innerHTML) }) onBeforeUnmount((){console.log(onBeforeUnmount,div.value) }) onUnmounted((){console.log(onUnmounted,div.value) }) function change() {divText.value 我是div改变后的 } /scripttemplatediv{{refData}}/divdiv refdiv{{divText}}/divbutton clickchange改变/button /templatestyle scoped/style 执行图片 父子组件传参 父--- 子 父组件通过v-bind绑定一个数据然后子组件通过defineProps接受传过来的值 如果说只传一个字符串的话不需要使用v-bind 案例 子组件 通过defineProps方法参数传一个对象将要接受的数据通过属性的方式写入如果要进行一些配置也可以使用对象的形式进行配置如title script setup langts defineProps({title: {type: String,default: Hello World},list: Array }) /scripttemplatedivh1{{ title }}/h1ulli v-for(item,index) in list :keyindex{{ item }}/li/ul/div /templatestyle scoped/style 如果要在setup内使用就需要接受defineProps的返回值返回值为对象类型属性就是传过来的数据 const data defineProps({   title: {     type: String,     default: Hello World   },   list: Array }) data.title 使用ts的方式一泛型的方式去接受数据 defineProps{title: string,list: number[] }() 如果像指定默认值需要使用withDefaults方法在第二个参数处以对象属性的形式指定为了防止引用冲突数组对象等采用工厂形式返回 withDefaults(defineProps{title: string,list: number[] }(), {title: default title,list: () [1,2,3] }) 父组件内 script setup langts import BaseRefAndReactive from ./components/BaseRefAndReactive.vue; import {ref} from vue; const list ref([1,2,3,4,5])/scripttemplateBaseRefAndReactive title这是标题 :listlist/BaseRefAndReactive /templatestyle scoped/style子---- 父 子组件给父组件传参 是通过defineEmits派发一个事件绑定一个自定义事件通过一些vue有的事件去触发这个emit从而达到传值的目的 子组件内 script setup langts withDefaults(defineProps{title: string,list: number[] }(), {title: default title,list: () [1,2,3] }) let emit defineEmits([on-click]) const handleClick () {emit(on-click, 我是子组件1,123,as,{name:张三}) } /scripttemplatedivh1{{ title }}/h1ulli v-for(item,index) in list :keyindex{{ item }}/li/ulbutton clickhandleClick传值/button/div /templatestyle scoped/style 使用ts的方式限制参数更加严格 let emit defineEmits{(e: on-click, name: string,age: number): void }() const handleClick () {emit(on-click, zhangsan, 18) } 父组件 script setup langts import BaseRefAndReactive from ./components/BaseRefAndReactive.vue; import {ref} from vue; const list ref([1,2,3,4,5]) const handleClick (name:string,...args) {console.log(name,父------)console.log(args) } /scripttemplateBaseRefAndReactive title这是标题 :listlist on-clickhandleClick/BaseRefAndReactive /templatestyle scoped/style子组件暴露给父组件内部属性 通过defineExpose 子组件 script setup langts import { ref,reactive } from vue const list reactive([1,2,3,4,5]) const str ref(hello) defineExpose({list,str }) /scripttemplatedivpref:{{str}}/p/div /templatestyle scoped/style 父组件 script setup langts import BaseRefAndReactive from ./components/BaseRefAndReactive.vue; import {ref,onMounted} from vue; let refBase ref(null); onMounted((){console.log(refBase.value); }) /scripttemplateBaseRefAndReactive refrefBase/BaseRefAndReactive /templatestyle scoped/style注意需要在onMounted里打印的原因是setup的生命周期早于子组件挂载也就是子组件还没有挂载就打印输出所以会是undefined
http://www.w-s-a.com/news/240684/

相关文章:

  • 域名和网站备案一样吗wordpress 封装 app
  • 婚纱摄影网站开题报告c2c模式是什么意思
  • 网站几种颜色wordpress水平菜单
  • php做网站的分站wordpress边下边看
  • 杭州建设实名制报备网站Wordpress外贸网站搭建公司
  • 山西云起时网站建设计算机网站开发实现总结
  • 一个网站做两个优化可以做吗永清网站建设
  • wordpress英文采集wordpress seo 链接
  • 进入建设银行的网站就打不了字工程建设标准化网站
  • 杭州网站推广大全网站建设演讲稿
  • 厦门网站的制作太仓专业网站建设
  • 天津公司网站建设公司哪家好在阿里巴巴国际网站上需要怎么做
  • 网站关键词seo推广公司哪家好无锡市无锡市住房和城乡建设局网站
  • 开远市新农村数字建设网站网站如何做QQ登录
  • 自己做个网站教程高端网站开发哪家强
  • 网站模板免费下载中文版大连网站建设哪家专业
  • 网站建设的基本代理公司注册公司坑人
  • 企业网站被黑后如何处理wordpress邮件发送类
  • 北京网站的网站建设公司建设工程竣工验收消防备案网站
  • 淄博市 网站建设报价wordpress里的发消息给我
  • 网站下拉菜单怎么做游戏网站模板免费下载
  • 阿里云上做网站套模板怎么做一个网站开发小组
  • 营销型网站源码下载青岛做网站建设的公司哪家好
  • 迁西网站定制怎么制作网址内容
  • 深圳装饰公司网站宁波网站建设哪里有
  • 建站网站破解版怎么看自己的网站是用什么做的
  • 做微商那个网站好织梦模板更新网站
  • 网站注册表单怎么做手机做网站需要多少天
  • 书店商城网站html模板下载企业网站建设方案书范文
  • 建设网站是普通办公吗快速排名seo软件