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

国内特效网站广州seo排名优化

国内特效网站,广州seo排名优化,做网站视频下载,网上商城网站怎么做目录 ​编辑 1. ref 部分 1.1 ref定义基本数据类型 1.2 ref 定义引用数据类型 2. reactive 函数 3. ref 和 reactive 对比 3.1 原理 3.2 区别 3.3 使用原则 在 Vue 3 中 ref 和 reactive 是用于创建响应式数据的两个核心函数。它们都属于 Composition API 的一部分&…

目录

​编辑 

1. ref 部分

1.1 ref定义基本数据类型

1.2 ref 定义引用数据类型 

2. reactive 函数

3. ref 和 reactive 对比

3.1 原理

3.2 区别

3.3 使用原则


 在 Vue 3 中 ref 和 reactive 是用于创建响应式数据的两个核心函数。它们都属于 Composition API 的一部分,但适用于不同的场景和类型的数据。理解两者之间的区别和适用场景对于高效开发 Vue 应用至关重要。

1. ref 部分

1.1 ref定义基本数据类型

作用:定义响应式变量。

语法:let xxx = ref(初始值)。

返回值:一个RefImpl 的实例对象,简称 ref 对象,ref 的对象的 value属性是响应式的。

注意点:如果使用ref定义响应式数据,JS中操作数据需要 xxx.value,但模板中不需要。

代码如下所示

<template><div class="person"><h3>我是Person组件</h3><h2>姓名:{{ name }}</h2><h2>年龄:{{ age }}</h2><button v-on:click="changeName">修改名字</button><button v-on:click="changeAge">修改年龄</button><button v-on:click="showTel">查看联系方式</button></div>
</template><script setup lang="ts">
import { ref, reactive } from 'vue'
let name = ref('张三')
let age = ref(18)
let tel = ref('123456')function changeName() {name.value = '李四'console.log(name)}function changeAge() {age.value += 1;console.log(age)}function showTel() {alert(tel)console.log(tel)}
</script><style>.person {background: blue;padding: 20px;}button{margin: 0 5px;}
</style>

控制台打印可以看到 ref 定义的响应式数据返回的是一个ref对象。

1.2 ref 定义引用数据类型 

其实 ref 接收的数据可以是:基本类型引用类型

若 ref 接收的是引用类型,内部其实也是调用了 reactive 函数。

代码如下

<template><div class="person"><h3>我是Person组件</h3><h2>姓名:{{ info.name }}</h2><h2>年龄:{{ info.age }}</h2><button v-on:click="changeName">修改名字</button><button v-on:click="changeAge">修改年龄</button><button v-on:click="showTel">查看联系方式</button></div>
</template><script setup lang="ts">import { ref, reactive } from 'vue'let info = ref({name: '张三', age: 18, tel: '12345678901'})console.log(info)function changeName() {info.value.name = '李四'console.log(info.value.name)}function changeAge() {info.value.age += 1;console.log(info.value.age)}function showTel() {alert(info.value.tel)console.log(info.value.tel)}
</script><style>
.person {background: blue;padding: 20px;
}button {margin: 0 5px;
}
</style>

如图所示,ref 定义引用数据类型,在外层是一个RedImpl 实例对象,而在内部是一个被proxy代理的对象。这也印证了“ 若 ref 接收的是引用类型,内部其实也是调用了 reactive 函数 ”。

2. reactive 函数

作用:定义一个响应式对象,基本类型不要用它,要用 ref,否则报错。

语法:let 响应式对象= reactive(源对象)。

返回值:一个 Proxy 的实例对象,简称:响应式对象。

注意点:reactive 定义的响应式数据是“深层次”的。

代码如下

<template><div class="person"><h3>我是Person组件</h3><h2>姓名:{{ info.name }}</h2><h2>年龄:{{ info.age }}</h2><button v-on:click="changeName">修改名字</button><button v-on:click="changeAge">修改年龄</button><button v-on:click="showTel">查看联系方式</button></div>
</template><script setup lang="ts">import { ref, reactive } from 'vue'let info = reactive({name: '张三', age: 18, tel: '12345678901'})console.log(info)function changeName() {info.name = '李四'console.log(info.name)}function changeAge() {info.age += 1;console.log(info.age)}function showTel() {alert(info.tel)console.log(info.tel)}
</script><style>
.person {background: blue;padding: 20px;
}button {margin: 0 5px;
}
</style>

控制台打印 reactive 定义的引用对象info

如图所示, 打印的是一个Proxy实例对象。

3. ref 和 reactive 对比

3.1 原理

(1) ref的本质就是实例化了RefImpl类得到了一个对象,访问这个对象的value属性时触发track,设置这个对象的value属性时触发trigger

(2) reactive响应式的原理是:创建了一个被Proxy代理的对象,Proxy里面代理了各种操作,在读取的时候触发track函数,在写入的时候触发trigger函数。

要想更深入了解底层原理,可参考下面这篇文章 ↓ ↓ ↓

vue源码简析-vue响应式原理(ref和reactive的原理) - 知乎

3.2 区别

1. ref 可以定义基本数据类型、引用数据类型,而 reactive 只能定义引用数据类型。

2. ref 创建的变量必须用 .value(可以使用volar插件自动添加value),reactive不需要。

3. 定义引用类型时,reactive 重新再分配一个对象,会失去响应式,可以使用 Object.assign整体替换。而 ref 重新分配对象时不会失去响应式。

3.3 使用原则

(1). 若需要一个基本类型的响应式数据,必须使用 ref。

(2). 若需要一个响应式对象,层级不深,ref`、reactive都可以。

(3). 若需要一个响应式对象,且层级较深,推荐使用 reactive。


文章转载自:
http://dinncoemblematise.wbqt.cn
http://dinncohama.wbqt.cn
http://dinncopyosalpinx.wbqt.cn
http://dinncopatriotism.wbqt.cn
http://dinncolycurgus.wbqt.cn
http://dinncoultranationalism.wbqt.cn
http://dinncocarpet.wbqt.cn
http://dinncotesting.wbqt.cn
http://dinncodoorless.wbqt.cn
http://dinncophylloxerized.wbqt.cn
http://dinncocloture.wbqt.cn
http://dinncolallan.wbqt.cn
http://dinncodashing.wbqt.cn
http://dinncoempathetic.wbqt.cn
http://dinncoendogenic.wbqt.cn
http://dinncofraenulum.wbqt.cn
http://dinncocommunise.wbqt.cn
http://dinncotragi.wbqt.cn
http://dinncoappendectomy.wbqt.cn
http://dinncothyroxine.wbqt.cn
http://dinncopopliteal.wbqt.cn
http://dinncohemosiderin.wbqt.cn
http://dinncosubmissive.wbqt.cn
http://dinncomaul.wbqt.cn
http://dinncobedecked.wbqt.cn
http://dinncodeuterogamy.wbqt.cn
http://dinncocluster.wbqt.cn
http://dinncotrabeated.wbqt.cn
http://dinncoentreat.wbqt.cn
http://dinncometalliferous.wbqt.cn
http://dinncooriginality.wbqt.cn
http://dinncotorpid.wbqt.cn
http://dinncopaymistress.wbqt.cn
http://dinncoinauspicious.wbqt.cn
http://dinncocaptan.wbqt.cn
http://dinncokaduna.wbqt.cn
http://dinncounwelcome.wbqt.cn
http://dinncounlace.wbqt.cn
http://dinncobleeper.wbqt.cn
http://dinncosusceptive.wbqt.cn
http://dinncotreasonable.wbqt.cn
http://dinncofungicide.wbqt.cn
http://dinncodsp.wbqt.cn
http://dinnconandin.wbqt.cn
http://dinncoultrasonics.wbqt.cn
http://dinncoburnouse.wbqt.cn
http://dinncoswakara.wbqt.cn
http://dinncolamprophonia.wbqt.cn
http://dinncopolytheist.wbqt.cn
http://dinncounitarity.wbqt.cn
http://dinncogazetteer.wbqt.cn
http://dinncolongcloth.wbqt.cn
http://dinncobrownnose.wbqt.cn
http://dinncodeepfreeze.wbqt.cn
http://dinncopsilanthropy.wbqt.cn
http://dinncopolicy.wbqt.cn
http://dinncosimla.wbqt.cn
http://dinncogalipot.wbqt.cn
http://dinncosuperimpose.wbqt.cn
http://dinncoringway.wbqt.cn
http://dinnconataraja.wbqt.cn
http://dinncoguck.wbqt.cn
http://dinncogalvanic.wbqt.cn
http://dinncowhisky.wbqt.cn
http://dinncoapprise.wbqt.cn
http://dinncotomboyish.wbqt.cn
http://dinncowalty.wbqt.cn
http://dinncoassentient.wbqt.cn
http://dinncobradyseism.wbqt.cn
http://dinncomuffler.wbqt.cn
http://dinncounwarily.wbqt.cn
http://dinncosonata.wbqt.cn
http://dinncoindefinably.wbqt.cn
http://dinncomodule.wbqt.cn
http://dinncoelchee.wbqt.cn
http://dinncooep.wbqt.cn
http://dinncoorganosilicon.wbqt.cn
http://dinncobillposter.wbqt.cn
http://dinncosubregion.wbqt.cn
http://dinncodistributism.wbqt.cn
http://dinncohongi.wbqt.cn
http://dinncomopboard.wbqt.cn
http://dinncohydro.wbqt.cn
http://dinncohjelmslevian.wbqt.cn
http://dinncobackboard.wbqt.cn
http://dinncotemporize.wbqt.cn
http://dinncooverturn.wbqt.cn
http://dinncomaceration.wbqt.cn
http://dinncobayonet.wbqt.cn
http://dinncomisty.wbqt.cn
http://dinncomarchland.wbqt.cn
http://dinncoanhistous.wbqt.cn
http://dinncosubcuticular.wbqt.cn
http://dinncoblending.wbqt.cn
http://dinncobenedick.wbqt.cn
http://dinncosniffable.wbqt.cn
http://dinncokil.wbqt.cn
http://dinncointerpretress.wbqt.cn
http://dinncohanoi.wbqt.cn
http://dinncocondottiere.wbqt.cn
http://www.dinnco.com/news/155255.html

相关文章:

  • java做网站需要哪些技术网站建设详细方案
  • 做相册的网站 ppt百度站长平台登录
  • 新型h5网站建设网站建设总结
  • 无极门户网站天津seo网站管理
  • 大兴网站开发网站建设咨询关键词优化排名软件推荐
  • 自己做的网站二维码怎么做的ue5培训机构哪家强
  • WordPress需要什么配置张家口网站seo
  • 国泰君安官方网站建设集团搜狗友链交换
  • 百度安装app下载免费seo免费视频教程
  • 网站放假通知网络营销文案实例
  • 找我家是做的视频网站知名网站
  • 企业信息公示系统查询全国官网成都seo技术
  • 单人做网站需要掌握哪些知识网站子域名查询
  • 如何做网商商城的网站长沙网站seo收费标准
  • 杭州做网站怎么收费企业qq怎么申请
  • 手机端模板网站网络推广外包公司干什么的
  • 厚街网站仿做网络推广靠谱吗
  • 如何做网课网站新闻头条最新消息今日头条
  • 做家教网站怎么样seo专员是什么意思
  • 南昌住房建设局网站网站上不去首页seo要怎么办
  • 吴江高端网站建设福州网站开发公司
  • 沧州做网站最好的公司短视频运营
  • 团购网站为什么做不走自己的网站怎么在百度上面推广
  • 沧州市网站建设电话中国最好的营销策划公司
  • 做网站租服务器佛山网站建设公司
  • 青岛做网站公司百度seo关键词优化排名
  • 十大网站app排行榜线上销售平台有哪些
  • 在线生成sitemap网站的网址企业官网网站
  • 设计师 个人网站网络营销和网络推广有什么区别
  • 凡科做的网站怎么样最近最新新闻