?(1):defineProps:傳入要使用的props定義自定義屬性,傳遞過來的值具有響應式,和props一樣;
(2):defineEimts:傳入要自定義的事件,emit實例去傳入自定義事件的值,和$emit或context.emit一樣;
父組件:
<template><initInput :index="8" @changeInit="changeInit"></initInput>
</template><script lang="ts" setup>
import initInput from './computed/initInput.vue';
const changeInit = (e: any) => {console.log(e); // 100
}
</script>
子組件:
<template><div><el-button type="primary" @click="change">點擊</el-button></div>
</template>
<script lang="ts" setup>
import { onMounted, getCurrentInstance } from 'vue';
import { useRoute, useRouter } from 'vue-router';
// data數據
let { proxy: this_ }: any = getCurrentInstance();
let route = useRoute();
let router = useRouter();
// mounted
// methods方法
let props = defineProps({index: {type: Number,default: 0}
});
let emit = defineEmits(["changeInit"]);
const change = () => {console.log(props.index); // 8emit("changeInit", 100);
}
</script>
<style scoped lang='scss'>
</style>