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

满洲里建设局网站有免费推广平台

满洲里建设局网站,有免费推广平台,德州网络科技有限公司,免费网站申请注册步骤在 Vue3 中#xff0c;组合式 API 是一种新的编程模式#xff0c;它允许你更灵活地组织和重用代码。组合式 API 主要包括以下几个部分#xff1a; ref#xff1a;用于创建响应式数据。reactive#xff1a;用于创建一个响应式对象。toRefs#xff1a;将一个响应式对象转换…在 Vue3 中组合式 API 是一种新的编程模式它允许你更灵活地组织和重用代码。组合式 API 主要包括以下几个部分 ref用于创建响应式数据。reactive用于创建一个响应式对象。toRefs将一个响应式对象转换为普通对象。computed用于创建计算属性。watch用于监听数据变化。provide/inject用于跨组件通信。 ref 类似于vue2中的data(){return{}} 在 Vue3 中ref 用于创建响应式数据。以下是一个简单的 Vue3 代码示例 templatedivh1{{ count }}/h1button clickincrement增加/button/div /templatescript setup import { ref } from vue; //定义简单变量const count ref(0);function increment() {count.value;} // 定义复杂变量 const arr ref([0,1,2,1,3,4]) const obj ref({ name:Tom }) /scriptreactive 专门给object赋值的reactive只能用于复杂变量不能用于简单变量 在 Vue3 中reactive 用于创建一个响应式对象。以下是一个简单的 Vue3 代码示例 templatedivinput v-modelmessage placeholder请输入内容 /p{{ message }}/p/div /templatescript setup import { reactive } from vue;const state reactive({message: ,});/script在这个示例中我们使用 reactive 创建了一个名为 state 的响应式对象并将其返回。然后在模板中使用 v-model 指令将输入框的值与 state.message 进行双向绑定。这样当输入框的值发生变化时state.message 也会相应地更新。 toRefs 在 Vue3 中toRefs 用于将一个响应式对象转换为一个普通对象其中每个属性都是一个 ref。以下是一个简单的 Vue3 代码示例 templatedivinput v-modelmessage placeholder请输入内容 /p{{ message }}/p/div /templatescript setup import { reactive, toRefs } from vue;const state reactive({message: ,});const stateRefs toRefs(state);/script在这个示例中我们首先使用 reactive 创建了一个名为 state 的响应式对象。然后我们使用 toRefs 将 state 转换为一个普通对象 stateRefs其中每个属性都是一个 ref。最后我们将 stateRefs 解构并返回以便在模板中使用。 computed 在 Vue3 中可以使用 computed 函数来创建多个计算属性。以下是一个简单的 Vue3 代码示例 templatedivinput v-modelmessage placeholder请输入内容 /p{{ reversedMessage }}/pp{{ uppercaseMessage }}/p/div /templatescript setup import { ref, computed } from vue;const message ref(Hello Vue3!);const reversedMessage computed(() {return message.value.split().reverse().join();});const uppercaseMessage computed(() {return message.value.toUpperCase();});/script在这个示例中我们创建了两个计算属性reversedMessage 和 uppercaseMessage。它们分别返回 message 的反转字符串和大写字符串。我们将这两个计算属性解构并返回以便在模板中使用。 watch 在 Vue3 中watch 用于监听数据的变化。以下是一个简单的 Vue3 代码示例包括简单监听、深度监听和监听某一个 object 中的变量以及同时监听多个简单变量和多个复杂变量 templatedivinput v-modelmessage placeholder请输入内容 /p{{ reversedMessage }}/pp{{ uppercaseMessage }}/pp{{ person.name }}/p/div /templatescript setup import { ref, watch } from vue;const message ref(Hello Vue3!);const person ref({ name: John, age: 30 });// 简单监听watch(message, (newValue, oldValue) {console.log(message changed:, newValue, oldValue);});// 深度监听watch(() person.value, (newValue, oldValue) {console.log(person changed:, newValue, oldValue);}, { deep: true });// 监听某一个 object 中的变量const personName computed(() person.value.name);watch(personName, (newValue, oldValue) {console.log(person.name changed:, newValue, oldValue);});// 同时监听多个简单变量和多个复杂变量const numbers ref([1, 2, 3]);const complexObjects ref([{ a: 1 }, { b: 2 }]);watch([message, numbers, complexObjects], () {console.log(message, numbers or complexObjects changed);});/script在这个示例中我们创建了一个简单的 message 变量并使用 watch 函数进行监听。我们还创建了一个 person 对象并使用 watch 函数进行深度监听。接下来我们创建了一个计算属性 personName并使用 watch 函数监听它的变化。最后我们创建了两个数组 numbers 和 complexObjects并使用 watch 函数同时监听它们的变化。 父子组件的传值 vue3中 使用defineProps 和 defineEmits 进行父子组件的传值 父传子 子组件 templatediv这是子组件{{fatherName}}/div /templatescript setup const props defineProps({ fatherName:String })/script父组件 templatediv这是父组件和vue一样的传递方式child :fatherNamefatherName/child/div /templatescript setup import child from 子组件地址 import {ref} from vue const fatherNameref(父组件变量)/script子传父 子组件 templatediv这是子组件{{fatherName}}/div /templatescript setup const props defineEmits([setChildname]) const sendtoFather(){ emit(setChildname,向父组件传值) } /script父组件 templatediv这是父组件child setChildnamegetChildname/child/div /templatescript setup import child from 子组件地址 count getChildname(data){ data就是来自子组件传递的参数 }/script顶级向底级传参 provide/inject用于跨组件通信。 vue2中是使用$evenbus这样的全局变量来传递变量其中使用的就是$emit 和$on来传递数据但是vue3中没有$on这个方法 传递值 provide template/templatescript setup import {provide} from vue provide(setname,这是传递的参数) /script接收值inject templatediv这是接收的值{{getName}}/div /templatescript setup import {inject} from vue const getNameinject(setname) /script注意provide/inject用于跨组件通信只是用于顶级向底级传参就是从上到下的传递 $ref 父组件通过$ref 调用子组件的方法并传值 vue3中 子组件还可以使用defineExpose来暴露方法和变量来让父组件获取到子组件的数据 子组件 templatediv这是子组件/div /templatescript setup import {ref} from vueconst name ref(子组件名字)const childFun (data){子组件的方法 } defineExpose({ name, chiildFun }) /script父组件 templatediv这是父组件child refchild/child 子组件的name:{{childObj}}/div /templatescript setup import child from 子组件地址 import {ref} from vueconst child ref(null)const dochiildFun(){child.value.chiildFun({id:1,age:30})} /script
http://www.w-s-a.com/news/81410/

相关文章:

  • 恒通建设集团有限公司网站企业网站百度指数多少算竞争大
  • 雅虎网站收录提交入口如何使用wordpress搭建网站
  • 微商城网站建设怎么样发稿是什么意思
  • dz建站与wordpress群晖做网站服务器速度快吗
  • 做手机网站的公司网站建设 app开发 图片
  • 网站开发技术背景介绍wordpress数据库重置密码
  • 开发建设网站的实施过程是一个logo设计品牌
  • 做360pc网站排名首页工程造价信息网官网首页
  • 产品销售网站模块如何设计大数据和网站开发
  • 现在帮别人做网站赚钱不济南做网站建设公司
  • 嘉兴网站建设哪家好最近三天的国际新闻大事
  • 安丘网站建设制作做网站口碑比较好的大公司
  • 成都专业做网站公司哪家好优化大师下载安装免费
  • 防蚊手环移动网站建设广东深圳有几个区
  • 网站建设找哪些平台宜兴网站开发
  • 免费网站应用软件wordpress添加动态图标
  • 中小企业网站建设客户需求调查问卷昆明网站建设一条龙
  • 网站内容的特点wordpress 移动端网页
  • 专门网站建设培训网站系统建设
  • 自己设计手机的网站wordpress主题加密教程
  • 北京网站建设公司飞沐卖水果网站建设的策划书
  • 北京免费自己制作网站短视频宣传片制作
  • 怎样进入谷歌网站电子商务网站建设软件选择
  • 建个普通网站多少钱设计师培训多少
  • 建设校园网站的意义视频链接提取下载
  • 天津电子商务网站wordpress安装图片
  • 青岛房产网站东莞网络营销外包公司
  • 网站建设中的页数网上工伤做实网站
  • 给公司做网站这个工作怎么样wordpress不支持中文标签
  • 湖南网站推广优化cc域名做门户网站