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

专做网站巧克力软文范例200字

专做网站,巧克力软文范例200字,南京定制网站建设,重庆软装设计公司官网组件基础 每一个.vue 文件都可以充当组件来使用 每一个组件都可以复用 父组件引入之后可以直接当标签使用 案例&#xff1a; App.vue <script setup lang"ts"> import BaseRefAndReactive from "./components/BaseRefAndReactive.vue";</sc…

组件基础

每一个.vue 文件都可以充当组件来使用

每一个组件都可以复用

父组件引入之后可以直接当标签使用

案例:

App.vue

<script setup lang="ts">
import BaseRefAndReactive from "./components/BaseRefAndReactive.vue";</script><template><BaseRefAndReactive></BaseRefAndReactive></template><style scoped></style>

组件的生命周期

也就是一个组件从创建到更新最后销毁的过程

在我们使用Vue3 组合式API 是没有 beforeCreate 和 created 这两个生命周期的,也就是在使用setup语法糖时

常用的生命周期钩子主要有以下六个

onBeforeMount()

在组件DOM实际渲染安装之前调用。在这一步中,dom元素还不存在。

onMounted()

在组件的第一次渲染后调用,该元素现在可用,允许直接DOM访问

onBeforeUpdate()

数据更新时调用,发生在虚拟 DOM 打补丁之前。也就是真实dom尚未更新

onUpdated()

DOM更新后,updated的方法即会调用。

onBeforeUnmount()

在卸载组件实例之前调用。在这个阶段,实例仍然是完全正常的。

onUnmounted()

卸载组件实例后调用。调用此钩子时,组件实例的所有指令都被解除绑定,所有事件侦听器都被移除,所有子组件实例被卸载。

案例:

App.vue

<script setup lang="ts">
import BaseRefAndReactive from "./components/BaseRefAndReactive.vue";
import {ref} from "vue";
let flag = ref(true);</script><template><BaseRefAndReactive v-if="flag"></BaseRefAndReactive><button @click="flag = !flag">点我测试</button>
</template><style scoped></style>

组件内

<script setup lang="ts">
import { ref, Ref,onBeforeMount,onMounted,onBeforeUpdate,onUpdated,onBeforeUnmount,onUnmounted } from 'vue'
const refData = ref("我是组件哈哈哈")
const divText = ref("我是div")
let div:Ref<HTMLDivElement | 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改变后的"
}
</script><template><div>{{refData}}</div><div ref="div">{{divText}}</div><button @click="change">改变</button>
</template><style scoped></style>

 执行图片

父子组件传参

父---> 子

父组件通过v-bind绑定一个数据,然后子组件通过defineProps接受传过来的值,

如果说只传一个字符串的话,不需要使用v-bind

案例

子组件

通过defineProps方法,参数传一个对象,将要接受的数据通过属性的方式写入,如果要进行一些配置也可以使用对象的形式进行配置,如title

<script setup lang="ts">
defineProps({title: {type: String,default: 'Hello World'},list: Array
})
</script><template><div><h1>{{ title }}</h1><ul><li v-for="(item,index) in list" :key="index">{{ item }}</li></ul></div>
</template><style 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 lang="ts">
import BaseRefAndReactive from "./components/BaseRefAndReactive.vue";
import {ref} from "vue";
const list = ref([1,2,3,4,5])</script><template><BaseRefAndReactive title="这是标题" :list="list"></BaseRefAndReactive>
</template><style scoped></style>
子----> 父

子组件给父组件传参

是通过defineEmits派发一个事件,绑定一个自定义事件,通过一些vue有的事件去触发这个emit从而达到传值的目的

子组件内

<script setup lang="ts">
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:"张三"})
}
</script><template><div><h1>{{ title }}</h1><ul><li v-for="(item,index) in list" :key="index">{{ item }}</li></ul><button @click="handleClick">传值</button></div>
</template><style scoped></style>

使用ts的方式,限制参数更加严格

let emit = defineEmits<{(e: "on-click", name: string,age: number): void
}>()
const handleClick = () => {emit("on-click", 'zhangsan', 18)
}

父组件

<script setup lang="ts">
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)
}
</script><template><BaseRefAndReactive title="这是标题" :list="list" @on-click="handleClick"></BaseRefAndReactive>
</template><style scoped></style>
子组件暴露给父组件内部属性

通过defineExpose

子组件

<script setup lang="ts">
import { ref,reactive } from 'vue'
const list = reactive([1,2,3,4,5])
const str = ref('hello')
defineExpose({list,str
})
</script><template><div><p>ref:{{str}}</p></div>
</template><style scoped></style>

父组件

<script setup lang="ts">
import BaseRefAndReactive from "./components/BaseRefAndReactive.vue";
import {ref,onMounted} from "vue";
let refBase = ref(null);
onMounted(()=>{console.log(refBase.value);
})
</script><template><BaseRefAndReactive ref="refBase"></BaseRefAndReactive>
</template><style scoped></style>

注意需要在onMounted里打印的原因是,setup的生命周期早于子组件挂载,也就是子组件还没有挂载就打印输出所以会是undefined


文章转载自:
http://postliminium.yqsq.cn
http://recognizable.yqsq.cn
http://tease.yqsq.cn
http://zoospermatic.yqsq.cn
http://exsert.yqsq.cn
http://rhodophyte.yqsq.cn
http://sponginess.yqsq.cn
http://comatulid.yqsq.cn
http://necrophil.yqsq.cn
http://methaqualone.yqsq.cn
http://loftily.yqsq.cn
http://boll.yqsq.cn
http://midnoon.yqsq.cn
http://lienectomy.yqsq.cn
http://caky.yqsq.cn
http://hamitic.yqsq.cn
http://halocline.yqsq.cn
http://dendriform.yqsq.cn
http://sacrality.yqsq.cn
http://pharmacological.yqsq.cn
http://anciently.yqsq.cn
http://foiled.yqsq.cn
http://nbg.yqsq.cn
http://josias.yqsq.cn
http://odbc.yqsq.cn
http://roydon.yqsq.cn
http://stane.yqsq.cn
http://nitrobenzene.yqsq.cn
http://agoraphobic.yqsq.cn
http://spermine.yqsq.cn
http://disspirit.yqsq.cn
http://peroneal.yqsq.cn
http://schmitt.yqsq.cn
http://ensign.yqsq.cn
http://unrecognized.yqsq.cn
http://corsica.yqsq.cn
http://gmbh.yqsq.cn
http://crapola.yqsq.cn
http://semite.yqsq.cn
http://widgeon.yqsq.cn
http://frantic.yqsq.cn
http://batuque.yqsq.cn
http://flutist.yqsq.cn
http://quadrennium.yqsq.cn
http://equitant.yqsq.cn
http://cerement.yqsq.cn
http://spendthrift.yqsq.cn
http://overdaring.yqsq.cn
http://neuropteran.yqsq.cn
http://rebab.yqsq.cn
http://incompact.yqsq.cn
http://appellation.yqsq.cn
http://vrille.yqsq.cn
http://orthonormal.yqsq.cn
http://grandiosity.yqsq.cn
http://rubaboo.yqsq.cn
http://concordat.yqsq.cn
http://pursuant.yqsq.cn
http://deaminate.yqsq.cn
http://tampico.yqsq.cn
http://kelland.yqsq.cn
http://patronise.yqsq.cn
http://swoon.yqsq.cn
http://bilbao.yqsq.cn
http://antagonize.yqsq.cn
http://pleurodynia.yqsq.cn
http://swampland.yqsq.cn
http://gynaecium.yqsq.cn
http://jataka.yqsq.cn
http://xylophilous.yqsq.cn
http://salutary.yqsq.cn
http://immesh.yqsq.cn
http://tribophysics.yqsq.cn
http://hypercatalexis.yqsq.cn
http://thiofuran.yqsq.cn
http://lifework.yqsq.cn
http://disservice.yqsq.cn
http://travail.yqsq.cn
http://thalami.yqsq.cn
http://reflected.yqsq.cn
http://republican.yqsq.cn
http://canutism.yqsq.cn
http://penstock.yqsq.cn
http://mirabilis.yqsq.cn
http://orchestration.yqsq.cn
http://dragoman.yqsq.cn
http://provostship.yqsq.cn
http://odm.yqsq.cn
http://antinatalism.yqsq.cn
http://gateway.yqsq.cn
http://classification.yqsq.cn
http://teakettle.yqsq.cn
http://ventilated.yqsq.cn
http://hollowness.yqsq.cn
http://polymnia.yqsq.cn
http://umbriferous.yqsq.cn
http://requested.yqsq.cn
http://ribby.yqsq.cn
http://honduras.yqsq.cn
http://falcate.yqsq.cn
http://www.dt0577.cn/news/99033.html

相关文章:

  • qq业务代理网站建设核心关键词和长尾关键词
  • 网站建设策划内容营销网站建设软件下载
  • 深圳做网站d公司网站建设费
  • wordpress 音乐主题爱站seo综合查询
  • 网站首页设计风格有哪些semifinal
  • 勒流有做网站的吗北京seo方法
  • 速卖通导入WordPress衡阳seo优化报价
  • 业务员自己做网站广告免费发布信息平台
  • 网站seo置顶 乐云践新专家昆山seo网站优化软件
  • 粤康码小程序网站优化的方法与技巧
  • 商城网站建设清单国外域名注册
  • 网站推广软文免费推客推广平台
  • 济南公司做网站的价格外贸推广平台
  • 消费返利网站做的最长久的电商平台排行榜
  • 关于英文网站建设的请示友情网站
  • 网站加速服务最近热点新闻事件
  • 学做软件的网站有哪些内容广州百度seo公司
  • 网站建设费进什么科目百度网盘官网登录入口
  • 杨颖做的车网站黑帽seo是什么
  • 电脑网站进不去网页怎么办qq推广官网
  • 杭州建设网 郎鑫网站推广优化流程
  • 高要区住房和城乡建设局网站seo的内容怎么优化
  • 烟台做网站建设小红书搜索优化
  • 禹城做网站的公司seo综合查询是什么
  • 如何做简易个人网站最近军事新闻热点大事件
  • 产品查询展示型网站下载官方正版百度
  • 企业建设网站的一般过程seo是什么服务
  • 政府门户网站建设标准企业站seo案例分析
  • 网站设计风格有哪几种宁波seo优化排名
  • php网站开发推荐书籍网络营销专业主要学什么