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

设计师招聘网成都最好的seo外包

设计师招聘网,成都最好的seo外包,室内设计软件哪个比较好,天津做网站企业1 认识Composition API Options API的弊端 setup函数 2 setup函数的参数 3 setup简单使用 1 注意不再有响应式数据 要做到响应式数据需要在数据定义时使用ref包装数据,并且在使用时,使用value解包 2 注意template要使用的数据或者函数,必须要return 返回才能被使用 <templa…

1 认识Composition API

Options API的弊端

在这里插入图片描述
在这里插入图片描述

setup函数

在这里插入图片描述

2 setup函数的参数

在这里插入图片描述

3 setup简单使用

1 注意不再有响应式数据
要做到响应式数据需要在数据定义时使用ref包装数据,并且在使用时,使用value解包

2 注意template要使用的数据或者函数,必须要return 返回才能被使用

<template><div class="app"><!-- template中ref对象自动解包 --><h2>当前计数: {{ counter }}</h2><button @click="increment">+1</button><button @click="decrement">-1</button></div>
</template><script>
import { ref } from 'vue'export default {setup() {// 1.定义counter的内容// 默认定义的数据都不是响应式数据let counter = ref(100)const increment = () => {counter.value++console.log(counter.value)}const decrement = () => {counter.value--}return {counter, increment, decrement }}
}
</script><style>
</style>

setup函数的返回值

在这里插入图片描述

4 为数据提供响应式的特性

1 Reactive API,复杂数据类型

在这里插入图片描述

2 Ref API,简单数据类型包装

ref可以简单数据类型包装,ref也可以定义复杂的数据
在这里插入图片描述

<template><div>//普通数据<h2>message: {{ message }}</h2><button @click="changeMessage">修改message</button><hr>//通过Reactive提供响应式数据<h2>账号: {{ account.username }}</h2><h2>密码: {{ account.password }}</h2><button @click="changeAccount">修改账号</button><hr>//通过Ref提供响应式数据<!-- 默认情况下在template中使用ref时, vue会自动对其进行解包(取出其中value) --><h2>当前计数: {{ counter }}</h2><button @click="increment">+1</button><button @click="counter++">+1</button></div>
</template><script>import { reactive, ref } from 'vue'export default {setup() {// 1.定义普通的数据: 可以正常的被使用// 缺点: 数据不是响应式的let message = "Hello World"function changeMessage() {message = "你好啊,李银河!"console.log(message)}// 2.定义响应式数据// 2.1.reactive函数: 定义复杂类型的数据const account = reactive({username: "coderwhy",password: "123456"})function changeAccount() {account.username = "kobe"}// 2.2.ref函数: 定义简单类型的数据(也可以定义复杂类型的数据)// counter定义响应式数据const counter = ref(0)function increment() {counter.value++}return {message,changeMessage,account,changeAccount,counter,increment,info}}}
</script><style scoped>
</style>

3 Reactive 和 ref 的应用场景

 setup() {// 定义响应式数据: reactive/ref// 强调: ref也可以定义复杂的数据const info = ref({})console.log(info.value)// 1.reactive的应用场景// 1.1.条件一: reactive应用于本地的数据// 1.2.条件二: 多个数据之间是有关系/联系(聚合的数据, 组织在一起会有特定的作用)const account = reactive({username: "coderwhy",password: "1234567"})const username = ref("coderwhy")const password = ref("123456")// 2.ref的应用场景: 其他的场景基本都用ref(computed)// 2.1.定义本地的一些简单数据const message = ref("Hello World")const counter = ref(0)const name = ref("why")const age = ref(18)// 2.定义从网络中获取的数据也是使用ref// const musics = reactive([])const musics = ref([])onMounted(() => {const serverMusics = ["海阔天空", "小苹果", "野狼"]musics.value = serverMusics})return {account,username,password,name,age}}}
</script>

5 computed

在这里插入图片描述

6 在setup中使用ref获取元素或者组件

在这里插入图片描述

7 生命周期钩子

在这里插入图片描述

8 侦听数据的变化 watch

在这里插入图片描述

<template><div>AppContent</div><button @click="message = '你好啊,李银河!'">修改message</button><button @click="info.friend.name = 'james'">修改info</button>
</template><script>import { reactive, ref, watch } from 'vue'export default {setup() {// 1.定义数据const message = ref("Hello World")const info = reactive({name: "why",age: 18,friend: {name: "kobe"}})// 2.侦听数据的变化watch(message, (newValue, oldValue) => {console.log(newValue, oldValue)})watch(info, (newValue, oldValue) => {console.log(newValue, oldValue)console.log(newValue === oldValue)}, {//立即执行一次immediate: true})// 3.监听reactive数据变化后, 获取普通对象,而不是代理对象watch(() => ({ ...info }), (newValue, oldValue) => {console.log(newValue, oldValue)}, {immediate: true,deep: true})return {message,info}}}
</script><style scoped>
</style>

侦听自动捕获依赖:watchEffect

在这里插入图片描述
在这里插入图片描述

<template><div><h2>当前计数: {{ counter }}</h2><button @click="counter++">+1</button><button @click="name = 'kobe'">修改name</button></div>
</template><script>import { watchEffect, watch, ref } from 'vue'export default {setup() {const counter = ref(0)const name = ref("why")// watch(counter, (newValue, oldValue) => {})// 1.watchEffect传入的函数默认会直接被执行// 2.在执行的过程中, 会自动的收集依赖(依赖哪些响应式的数据)const stopWatch = watchEffect(() => {console.log("-------", counter.value, name.value)// 判断counter.value > 10if (counter.value >= 10) {//停止监听stopWatch()}})return {counter,name}}}
</script><style scoped>
</style>

9 hook封装

Composition API的主要作用就是利用函数式编程,可以很容易的将可以复用的代码抽取出来(因为代码可以写在一起),这些被抽取的,单独功能的代码,被称为hook(钩子).不是真正的hook,而是类似hook的能力.

hook的作用和组件一样都是封装,然而组件偏向于UI的封装,而hook偏向于功能逻辑,状态管理.
也就是说Vue3可以利用Composition API将optionsAPI的内容,抽取为hook功能,给组件使用,组件的功能被抽取出来了,只剩下UI由组件实现.

1 hook封装,计数器

useCounter.js

import { ref, onMounted } from 'vue'export default function useCounter() {const counter = ref(0)function increment() {counter.value++}function decrement() {counter.value--}//模拟网络环境,初始化值onMounted(() => {setTimeout(() => {counter.value = 989}, 1000);})return {counter,increment,decrement}
}

2 使用hook

<template><h2>About计数: {{ counter }}</h2><button @click="increment">+1</button><button @clcik="decrement">-1</button>
</template><script>import useCounter from '../hooks/useCounter'export default {setup() {//使用hook函数//const { counter, increment, decrement } = useCounter()// return {//   counter,//   increment,//   decrement,//   }return {//使用hook函数的等价写法...useCounter()}}}
</script>

10 script setup语法糖

在这里插入图片描述
使用这种语法糖,在需要使用组件时,不再需要使用components声明,只要import导入就可以直接使用

顶层的绑定会被暴露给模板

在这里插入图片描述


文章转载自:
http://amphiphyte.Ljqd.cn
http://feint.Ljqd.cn
http://propitious.Ljqd.cn
http://dead.Ljqd.cn
http://homopolymer.Ljqd.cn
http://casern.Ljqd.cn
http://trochee.Ljqd.cn
http://lipping.Ljqd.cn
http://deliveryman.Ljqd.cn
http://yah.Ljqd.cn
http://damselfish.Ljqd.cn
http://suberin.Ljqd.cn
http://bookmaker.Ljqd.cn
http://ajutage.Ljqd.cn
http://fishbone.Ljqd.cn
http://xanthin.Ljqd.cn
http://disenchant.Ljqd.cn
http://bushcraft.Ljqd.cn
http://overdone.Ljqd.cn
http://aleksandrovsk.Ljqd.cn
http://jollo.Ljqd.cn
http://sultana.Ljqd.cn
http://zetz.Ljqd.cn
http://personal.Ljqd.cn
http://seamster.Ljqd.cn
http://lotiform.Ljqd.cn
http://family.Ljqd.cn
http://barrister.Ljqd.cn
http://pesterous.Ljqd.cn
http://metralgia.Ljqd.cn
http://saanen.Ljqd.cn
http://faultless.Ljqd.cn
http://sypher.Ljqd.cn
http://heldentenor.Ljqd.cn
http://pustulation.Ljqd.cn
http://hieroglyph.Ljqd.cn
http://clidomancy.Ljqd.cn
http://nd.Ljqd.cn
http://con.Ljqd.cn
http://intriguing.Ljqd.cn
http://puncturable.Ljqd.cn
http://pluviose.Ljqd.cn
http://obturator.Ljqd.cn
http://linnet.Ljqd.cn
http://unhung.Ljqd.cn
http://disputably.Ljqd.cn
http://phare.Ljqd.cn
http://unacquaintance.Ljqd.cn
http://insectarium.Ljqd.cn
http://seiche.Ljqd.cn
http://quahaug.Ljqd.cn
http://wonderland.Ljqd.cn
http://will.Ljqd.cn
http://lockpick.Ljqd.cn
http://semirevolution.Ljqd.cn
http://slaty.Ljqd.cn
http://heres.Ljqd.cn
http://otary.Ljqd.cn
http://baotou.Ljqd.cn
http://piezochemistry.Ljqd.cn
http://semicentenary.Ljqd.cn
http://vespucci.Ljqd.cn
http://furze.Ljqd.cn
http://ganelon.Ljqd.cn
http://gocart.Ljqd.cn
http://yb.Ljqd.cn
http://hertha.Ljqd.cn
http://efferent.Ljqd.cn
http://forborne.Ljqd.cn
http://vertu.Ljqd.cn
http://scrollwork.Ljqd.cn
http://banefully.Ljqd.cn
http://expire.Ljqd.cn
http://gentian.Ljqd.cn
http://atonalistic.Ljqd.cn
http://paraphernalia.Ljqd.cn
http://tribometer.Ljqd.cn
http://topi.Ljqd.cn
http://shakta.Ljqd.cn
http://spdos.Ljqd.cn
http://cheltonian.Ljqd.cn
http://patulin.Ljqd.cn
http://pareve.Ljqd.cn
http://astigmometer.Ljqd.cn
http://endosporous.Ljqd.cn
http://boaster.Ljqd.cn
http://hrs.Ljqd.cn
http://schlep.Ljqd.cn
http://innervate.Ljqd.cn
http://elastic.Ljqd.cn
http://elegit.Ljqd.cn
http://homophonous.Ljqd.cn
http://dekabrist.Ljqd.cn
http://prefixion.Ljqd.cn
http://synopsis.Ljqd.cn
http://chenag.Ljqd.cn
http://phytane.Ljqd.cn
http://vandalize.Ljqd.cn
http://stubby.Ljqd.cn
http://phelps.Ljqd.cn
http://www.15wanjia.com/news/70209.html

相关文章:

  • 百度文库怎么做网站排名关键词优化和seo
  • 网站是用什么技术做的济南seo快速霸屏
  • 怎么用css做网站网站设计开发网站
  • 电商网站设计规划书太原seo关键词排名优化
  • 一级域名做网站的好处注册推广
  • 网站怎么做动态背景图片有人看片吗免费观看视频
  • wordpress今天更新文章数深圳seo关键词优化外包公司
  • 徐州网站优化百度seo公司兴田德润
  • 方庄网站建设公司网页怎么做
  • 中山市饮食网站建设seo排名策略
  • 北京网站建设招聘2023新一轮病毒叫什么名字
  • 郑州网站制作电话新产品的推广销售方法
  • 视频付费点播网站怎么做吉林网站推广公司
  • 嘉兴网站建设公司营销软文范例
  • 宿州公司做网站百度健康
  • 广州市城市建设档案馆网站企业网站快速排名
  • 如何评判网站建设岗位b站推广入口
  • 政府网站建设 会议纪要高清的网站制作
  • 配件查询网站制作蚁坊软件舆情监测系统
  • 网站建设 首选百川互动怎么自己注册网站
  • 罗湖中心区做网站哪家竞价托管专业
  • 商城网站建设定制郑州seo推广外包
  • 网站关键字如何做网站推广优化教程
  • 西安网站推广慧创成品网站源码1688免费推荐
  • 电影推荐网站开发郑州网站关键词排名技术代理
  • 刚做网站做多用户还是单用户什么平台免费推广效果最好
  • 哪些网站做宾馆推广好重庆seo网页优化
  • 微信端怎么建设网站关键词代发排名推广
  • 1 设计一个企业网站外贸如何做网站推广
  • 郓城网站建设电话江西省水文监测中心