爱站网备案查询,环球资源网的定位,漂亮购物网站欣赏,大丰区城乡和住房建设局网站1、setup()的语法糖的用法
script标签上写setup属性#xff0c;不需要export default {} setup() 都可以省
创建每个属性或方法时也不需要return
导入某个组件时也不需要注册
script setup
// script标签上写setup属性#xff0c;不需要export default {} set…1、setup()的语法糖的用法
script标签上写setup属性不需要export default {} setup() 都可以省
创建每个属性或方法时也不需要return
导入某个组件时也不需要注册
script setup
// script标签上写setup属性不需要export default {} setup() 都可以省
import {ref} from vue//组合式api//创建响应式数据age初始值是10const ageref(10)const snameref(zs)//修改年龄的方法const increase(){age.value}//模板需要用的数据或方法需要 return/scripttemplate
divhello,world/div
p年龄{{ age }}/p
p姓名{{ sname }}/p
button clickincrease年龄1/button
/templatestyle scoped/style2、setup()的非语法糖的用法
创建多个数据就要return多个数据
setup() 组合式api的入口执行的时机比beforCreate还早
script
import {ref} from vue
export default {setup(){//组合式api//创建响应式数据age初始值是10const ageref(10)const snameref(zs)//修改年龄的方法const increase(){age.value}//模板需要用的数据或方法需要 returnreturn {age,increase,sname}}
}
/scripttemplate
divhello,world/div
p年龄{{ age }}/p
p姓名{{ sname }}/p
button clickincrease年龄1/button
/templatestyle scoped/style