【笔记】vue3.2 组件中引入其他组件
在vue3.2中,组件中定义的变量和方法不再需要return了,而是可以直接在模板中使用。<script setup>import { ref } from 'vue'const text = ref('点击')const handleClick = () => {console.log('click')}</script><template><bu
·
在vue3.2中,组件中定义的变量和方法不再需要
return
了,而是可以直接在模板中使用。
<script setup>
import { ref } from 'vue'
const text = ref('点击')
const handleClick = () => {
console.log('click')
}
</script>
<template>
<button @click="handleClick">{{ text }}</button>
</template>
就如上面的例子所展示的那样,组件中定义的变量或是方法,可以直接在模板中使用,那么如果引入的组件该如何在模板中使用呢?
在vue3.x中,引入的组件是需要在
components
中声明的,但是在vue3.2中,你可以直接使用。
还是上例子吧。
<script setup>
import CustomComponent from './CustomComponent/main.vue'
</script>
<template>
<CustomComponent></CustomComponent>
</template>
你没有看错,就是这么简单。
更多推荐
已为社区贡献1条内容
所有评论(0)