从实现上来看,defineComponent 只返回传递给它的对象。但是,就类型而言,返回的值有一个合成类型的构造函数,用于手动渲染函数、TSX 和 IDE 工具支持。
import { defineComponent } from 'vue'
const MyComponent = defineComponent({
data() {
return { count: 1 }
},
methods: {
increment() {
this.count++
}
}
})
或者是一个setup函数,函数名称将作为组件名称使用
import {ref,defineComponent} from 'vue';
const helloWorld = defineComponent(function helloWorld(){
const count = ref(0);
return {count};
})