vue3tup语法糖事件引⽤和写法
tup基础⽤法
tup是vue3新增的⼀个属性,默认写法是在代码中⽤tup⽅法,然后在tup中return。
tup(){
const func = () => {
炒白术的功效与作用//这⾥写⽅法⾥的内容
}
红烧牛尾return func
}
⽤tup语法糖则⽆需这么繁琐,并且不需要使⽤this,切记。
不倒翁的制作方法
<script tup>
/
/直接写⽅法,在dom中直接调⽤即可
const editFunc = () => {}
</script>期货策略
<template>
<div @click="editDrawer">编辑按钮</div>
</template>
tup中使⽤watch,props,emit
props⽤defineProps代替。
emit⽤defineEmits代替。
watch监听props,值以函数返回值的形式传⼊。
<script tup>
const props = defineProps({
rightMenuStyle: String,
rightMenu: String
})
const emit = defineEmits(['editDrawer'])
watch(()=>props.rightMenuStyle, (newVal, oldVal)=>{
if(val){
种植石斛state.styleObj = JSON.par(newVal)
}
}, {deep: true, immediate: true})
const editDrawer = (val) => {
正方形纸能折什么
emit('editDrawer', pe)
}
</script>
<template>
<div @click="editDrawer">编辑按钮</div>
</template>
watch监听多个值
watch([()=>props.rightMenuStyle, ()=>props.rightMenu], (newVal, oldVal)=>{
鱼的记忆有多久// 请注意,监听多个值,有⼀个值变化,watch就会执⾏,所以为了不频繁触发,不建议同时监听多个值
}, {deep: true, immediate: true})
预防校园欺凌内容| 本⽂章会⼀直更新,请持续关注哦,⼀起学习!