vue3笔记
在setup语法糖
- props方面
const props = defineProps({
show: {
type: Boolean,
default: false,
},
top: {
type: String,
default: ''
},
})
可以以对象形式添加那么就可以添加默认值。
props的vue3文档地址
- 子传父
const emit = defineEmits(['close']) // 是使用数组的方式
const close = () => {
emit('close')
}
然后父在子组件@close方法使用
defineProps和defineEmits不用引入默认有的。
3.计算属性
const avatar = computed(()=> {
return ''
})
// computed调用时需要回调的方式
引用组件的时候注意在要大写组件名称
比如你的组件是ListItem,那么这样引用,不然你就去找个天荒地老都不理解为什么失效。