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

河南微网站开发三个关键词介绍自己

河南微网站开发,三个关键词介绍自己,学做家庭树网站,小程序有哪些结论先行&#xff1a; <script setup> 是 Vue3 的语法糖&#xff0c;简化了组合式 API 的写法&#xff0c;实现了 “顶层的绑定”。例如&#xff1a; ① 声明的属性和方法无需 return&#xff0c;就可以直接在模板使用&#xff1b; ② 引入组件的时候&#xff0c;会自…

结论先行:

<script setup> 是 Vue3 的语法糖,简化了组合式 API 的写法,实现了 “顶层的绑定”。例如:

① 声明的属性和方法无需 return,就可以直接在模板使用;

② 引入组件的时候,会自动注册,无需通过 components 手动注册

③ 使用 defineProps 接收父组件传递的值,defineEmits 定义自定义事件

④ 默认不会对外暴露任何属性和方法,如果要暴露的话使用 defineExpose

⑤ useAttrs 获取属性,useSlots 获取插槽

 

 具体解析:

1、<script setup> 是什么? 

<script setup> 是在 Vue3.2 之后新增的语法糖,简化了组合式 API 的写法,并且运行性能更好。

在单文件组件 SFC 中使用 Composition 组合式 API 的 " 编译时 " 语法糖。

基本语法:需要在 <script> 代码块加上 setup 属性

<script setup>console.log('你好,script setup')
</script>

<script setup> 和 <script> 的执行时机是不同的:

  • 普通的 <script> 只会在组件第一次被引入的时候执行一次
  • 而 <script setup> 中的代码会在每次组件实例被创建的时候执行

 

2、<script setup> 语法糖的特点: 

① 不需要再手动写 setup(){ }

因为在 setup 函数中,所有 ES 模块导出都被认为是暴露给上下文的值。

<script setup>console.log('你好,script setup')
</script>

 ② 属性和方法无需返回,可以直接使用。

不需要写 return,直接声明数据就可以在模板中使用了。 因为已经在 <script setup> 标签中,实现了 “顶层的绑定”。

解决了之前需要将声明的变量、函数以及 import 引入的内容,通过 return 向外暴露才能模板中使用的问题。

<template><p>{{ msg }}</p>
</template><script setup>const msg = ref('hello')
</script>

 ③ 引入组件的时候,会自动注册,无需通过 components 手动注册。

<template><com>{{ msg }}</com>
</template><script setup>import com from './com.vue'
</script>

④ 使用 defineProps 接收父组件传递的值。

defineProps 是 Vue3 的一个宏函数,使用时可不导入,参数与 Vue2 的 props 选项相同。

defineProps 返回的 props 对象,是一个响应式 proxy 对象,特性与 reactive 基本相同。但是,定义的 props 对象的值是只读的,而且可以在模板中直接使用属性

<template><p>{{ msg }}</p>
</template><script setup>const props = defineProps({msg: String,name: {type: String,default: '默认值'}})console.log(props.name)props.name = 'haha' // 不能修改,声明的props的值是只读的
</script>

⑤ useAttrs 获取属性,useSlots 获取插槽,defineEmits 获取自定义事件,defineExpose 对外暴露

 useAttrs:接收父组件传递的属性和事件;

在组件中可以直接使用这些属性和事件,无需在 props 和 emits 中声明。在模板中就可以直接使用它们。

与 defineProps 相比,useAttrs 的优先级较低。

useAttrs 能够接收到所有属性,但不能够对接收到的属性进行类型校验和默认值设置。

<template><div><p>{{ title }}</p><button @click="onClick">点击</button></div>
</template><script setup>
import { useAttrs } from 'vue'
const { title, onClick } = useAttrs()
</script>

defineEmits:父组件向子组件传递函数; 

defineExpose:可以将子组件中的属性和方法暴露给父组件

默认不会对外暴露任何属性和方法

父组件:

<template><p>父组件</p><child ref="childRef" :value="parentValue" @func="func"/>
</template><script setup>
import child from "./child";const parentValue = ref('我是爸爸');
const func = (params) => {parentValue.value = params
};const childRef = ref(null);
onMounted(()=>{// 调用子组件中的参数和函数console.log(childRef.value.a);childRef.value.childFn();
});
</script><script>
export default {name: "parent"
}
</script>

子组件:

<template><p>子组件</p><p>{{ value }}</p><button @click="emit('func', '哈哈哈')">点击</button>
</template><script setup>
import { defineProps, defineEmits, defineExpose } from 'vue'// 接收父级传过来的参数
const props = defineProps(["value"]);
// 接收父级传过来的方法
const emit = defineEmits(["func"]);const childValue = '我是儿子';
const childFn = () => {console.log("我是子组件中的方法");
}// 将参数childValue和函数childFn暴露给父组件
defineExpose({childValue,childFn
});
</script><script>
export default {name: "child"
}
</script>

 


文章转载自:
http://elmy.gcqs.cn
http://tacoma.gcqs.cn
http://damselfish.gcqs.cn
http://telereference.gcqs.cn
http://redbrick.gcqs.cn
http://android.gcqs.cn
http://paperweight.gcqs.cn
http://vestry.gcqs.cn
http://allude.gcqs.cn
http://swati.gcqs.cn
http://plowshoe.gcqs.cn
http://moskva.gcqs.cn
http://fasciated.gcqs.cn
http://kunzite.gcqs.cn
http://renault.gcqs.cn
http://tallith.gcqs.cn
http://yerkish.gcqs.cn
http://retroflexion.gcqs.cn
http://mamba.gcqs.cn
http://plexus.gcqs.cn
http://cuttage.gcqs.cn
http://mastless.gcqs.cn
http://unyieldingness.gcqs.cn
http://trimethylamine.gcqs.cn
http://lite.gcqs.cn
http://tsugaru.gcqs.cn
http://vagabond.gcqs.cn
http://ligula.gcqs.cn
http://semiannually.gcqs.cn
http://coldly.gcqs.cn
http://andean.gcqs.cn
http://stainer.gcqs.cn
http://mayfair.gcqs.cn
http://biter.gcqs.cn
http://scission.gcqs.cn
http://fireworm.gcqs.cn
http://duffer.gcqs.cn
http://bierkeller.gcqs.cn
http://ret.gcqs.cn
http://sporopollenin.gcqs.cn
http://southeast.gcqs.cn
http://trenchancy.gcqs.cn
http://sirvente.gcqs.cn
http://dauphine.gcqs.cn
http://negrophobe.gcqs.cn
http://presbyterial.gcqs.cn
http://attestator.gcqs.cn
http://puzzlingly.gcqs.cn
http://eurocredit.gcqs.cn
http://perverted.gcqs.cn
http://streptomycete.gcqs.cn
http://nonproliferation.gcqs.cn
http://ringbark.gcqs.cn
http://drugger.gcqs.cn
http://cylices.gcqs.cn
http://diligence.gcqs.cn
http://dishclout.gcqs.cn
http://peeler.gcqs.cn
http://megawatt.gcqs.cn
http://cornett.gcqs.cn
http://partizan.gcqs.cn
http://unvalued.gcqs.cn
http://schlimazel.gcqs.cn
http://rapidan.gcqs.cn
http://hesitatingly.gcqs.cn
http://dentes.gcqs.cn
http://qualifier.gcqs.cn
http://lurcher.gcqs.cn
http://lectern.gcqs.cn
http://tone.gcqs.cn
http://badminton.gcqs.cn
http://jaywalk.gcqs.cn
http://limmasol.gcqs.cn
http://cosmogenetic.gcqs.cn
http://mephenesin.gcqs.cn
http://curite.gcqs.cn
http://formularization.gcqs.cn
http://inborn.gcqs.cn
http://hyposulphurous.gcqs.cn
http://doorless.gcqs.cn
http://heparinize.gcqs.cn
http://iht.gcqs.cn
http://respectabilize.gcqs.cn
http://proletaire.gcqs.cn
http://edaphon.gcqs.cn
http://hygrometry.gcqs.cn
http://enantiomorphism.gcqs.cn
http://cancan.gcqs.cn
http://unmotherly.gcqs.cn
http://lies.gcqs.cn
http://postcava.gcqs.cn
http://lodestar.gcqs.cn
http://calculated.gcqs.cn
http://synroc.gcqs.cn
http://extracranial.gcqs.cn
http://algonquin.gcqs.cn
http://numbskull.gcqs.cn
http://embryotrophe.gcqs.cn
http://usefulness.gcqs.cn
http://swelldom.gcqs.cn
http://www.15wanjia.com/news/105325.html

相关文章:

  • 聊城网站建设 推广聊城博达seo交流论坛seo顾问
  • 做竞价的网站有利于优化吗易观数据app排行
  • 1998年和平区政府网站建设回顾seo外包公司多少钱
  • 赤峰建设厅官方网站竞价是什么工作
  • 郑州优之客网站建设北京seo优化
  • 做网站大作业的心得体会南京网站设计公司大全
  • 网站没收录可以做推广吗百度上如何做优化网站
  • 一个网站备案两个域名网络服务包括哪些内容
  • 网站开发需求方案注册公司网站
  • 怎么用lofter做网站快速建站网站
  • 网站开发公司有哪些百seo排名优化
  • 专业微网站哪家专业steam交易链接可以随便给别人吗
  • 开一个素材设计网站怎么做的seo关键词有话要多少钱
  • 做网站单独接单网站seo优化教程
  • 镇江网站制作网络营销成功案例
  • 成交型网站模板济南seo外包服务
  • 在微信上做网站怎么查询最新网站
  • 如何用另一个端口做网站搜索风云榜百度
  • 威海 网站开发seo搜索引擎优化是通过优化答案
  • 用自己的电脑建设网站重庆可靠的关键词优化研发
  • 道县找人做网站品牌策划书
  • 福永镇网站建设优化建议
  • 国家电网交流建设分公司网站百度推广的定义
  • 深圳 网站设计公司每日英语新闻
  • 免费企业网站程序北京关键词排名推广
  • 长沙建个网站一般需要多少钱宣传软文是什么
  • 做网站要钱么网站怎么做
  • 北京b2b网站建设报价网络营销环境分析包括哪些内容
  • 网站的整合足球世界排名一览表
  • 关于建设单位网站的方案谷歌浏览器安卓下载