【发布时间】:2021-11-11 02:40:02
【问题描述】:
当我尝试使用 <script setup> 但不使用 <template> 编写 SFC 时,我在控制台 [Vue warn] Component is missing template or render function 中收到警告。
有什么解决办法吗?
【问题讨论】:
标签: vue.js vue-component vuejs3 vue-sfc vue-script-setup
当我尝试使用 <script setup> 但不使用 <template> 编写 SFC 时,我在控制台 [Vue warn] Component is missing template or render function 中收到警告。
有什么解决办法吗?
【问题讨论】:
标签: vue.js vue-component vuejs3 vue-sfc vue-script-setup
显然,您需要一个模板或渲染函数。由于不想使用模板,可以考虑使用渲染函数。
很遗憾,渲染功能似乎不适用于设置。
<script lang="ts">
export default defineComponent({
render() {
return h("div", {}, this.a);
}
});
</script>
<script lang="ts" setup>
import { defineComponent, ref, h } from "vue";
const a = ref(1);
</script>
<style scoped></style>
更多信息,您可以在此处查看render-function(official doc)。
【讨论】:
() => null
() => null 作为渲染函数。
Vuejs dev answers,在这种情况下可以使用空的<template>。
【讨论】: