const props = defineProps(['propMsg', 'propId'])
const props = defineProps({ propMsg: String, propId: { type: Number, required: false, default: 18 } })
<div>{{ propMsg }} - {{ props.propId }}</div>
import { computed } from 'vue'; const props = defineProps({ msg: String }) const comp = computed(() => { //return msg.toUpperCase() return props.msg.toUpperCase() })
<div>computed {{ comp }}</div>
import { ref } from 'vue'; import Test from './components/Test.vue'; let msg = ref('hi,there')
<Test :propMsg="msg" propId="18"></Test>
<Test :propId="18" />
<Test :propId="item.id" />
<Test isDone />
<Test :isDone="false" />
<Test :isDone="item.flag" />
<Test :arr="[1,2,3,4,5]" />
<Test :arr="item.list" />
<Test :obj="{id:1001, name:'glpla'}" />
<Test :obj="item.author" />
<List :lists="propLists"/>
<Swiper :imgUrl="propImgUrls" :swiperH="propSwiperH"/>
暴露参数,类型为函数;注意是 Function,不是 function
const props = defineProps({ closeFn: Function, confirmFn: Function })
使用方法
<button @click="closeFn">×</button> <button @click="confirmFn">confirm</button>
传递方法
<Msg :closeFn="closeFn" :confirmFn="confirmFn"></Msg>
定义事件处理函数
const closeFn = () => { } const confirmFn = () => { }